-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from PHOENIXCONTACT/migrate/remove-startup
Remove Startup.cs
- Loading branch information
Showing
4 changed files
with
123 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.Extensions.Options; | ||
using System.Threading.Tasks; | ||
|
||
namespace MyApplication.App | ||
{ | ||
public class ExamplePolicyProvider : DefaultAuthorizationPolicyProvider | ||
{ | ||
public ExamplePolicyProvider(IOptions<AuthorizationOptions> options) : base(options) | ||
{ | ||
} | ||
|
||
public override async Task<AuthorizationPolicy> GetPolicyAsync(string policyName) | ||
{ | ||
var policy = await base.GetPolicyAsync(policyName); | ||
|
||
if (policy == null) | ||
{ | ||
policy = new AuthorizationPolicyBuilder() | ||
.RequireClaim("Permission", policyName) | ||
.Build(); | ||
} | ||
return policy; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,106 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Controllers; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Moryx.Asp.Integration; | ||
using Moryx.Model; | ||
using Moryx.Runtime.Kernel; | ||
using Moryx.Tools; | ||
using MyApplication.App; | ||
using System.Globalization; | ||
using System.IO; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace MyApplication.App | ||
AppDomainBuilder.LoadAssemblies(); | ||
|
||
var builder = WebApplication.CreateBuilder(); | ||
var services = builder.Services; | ||
|
||
// Setup MORYX | ||
services.AddMoryxKernel(); | ||
services.AddMoryxModels(); | ||
services.AddMoryxModules(); | ||
|
||
#region Startup ConfigureServices | ||
services.AddSingleton<IAuthorizationPolicyProvider, ExamplePolicyProvider>(); | ||
|
||
services.AddLocalization(); | ||
services.Configure<RequestLocalizationOptions>(options => | ||
{ | ||
public class Program | ||
var supportedCultures = new[] | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
AppDomainBuilder.LoadAssemblies(); | ||
|
||
var host = Host.CreateDefaultBuilder(args) | ||
.ConfigureServices(serviceCollection => | ||
{ | ||
serviceCollection.AddMoryxKernel(); | ||
serviceCollection.AddMoryxModels(); | ||
serviceCollection.AddMoryxModules(); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
webBuilder.UseIISIntegration(); | ||
}) | ||
.Build(); | ||
|
||
host.Services.UseMoryxConfigurations("Config"); | ||
host.Services.StartMoryxModules(); | ||
|
||
host.Run(); | ||
|
||
host.Services.StopMoryxModules(); | ||
} | ||
} | ||
new CultureInfo("de-De"), | ||
new CultureInfo("en-De"), | ||
new CultureInfo("it-De"), | ||
new CultureInfo("zh-Hans"), | ||
}; | ||
|
||
options.SupportedCultures = supportedCultures; | ||
options.SupportedUICultures = supportedCultures; | ||
}); | ||
|
||
|
||
services.AddCors(options => | ||
{ | ||
options.AddPolicy("CorsPolicy", builder => builder | ||
.WithOrigins("http://localhost:4200") // Angular app url for testing purposes | ||
.AllowAnyMethod() | ||
.AllowAnyHeader() | ||
.AllowCredentials()); | ||
}); | ||
|
||
services.AddRazorPages(); | ||
|
||
services.AddControllers() | ||
.AddJsonOptions(jo => jo.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())); | ||
|
||
services.AddSwaggerGen(c => | ||
{ | ||
c.CustomOperationIds(api => ((ControllerActionDescriptor)api.ActionDescriptor).MethodInfo.Name); | ||
c.CustomSchemaIds(type => type.ToString()); | ||
}); | ||
#endregion | ||
|
||
var app = builder.Build(); | ||
var env = app.Environment; | ||
|
||
#region Startup Configure App | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
|
||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseRequestLocalization(); | ||
|
||
app.UseStaticFiles(); | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseRouting(); | ||
|
||
if (env.IsDevelopment()) | ||
app.UseCors("CorsPolicy"); | ||
|
||
app.UseAuthentication(); | ||
app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
var conventionBuilder = endpoints.MapControllers(); | ||
conventionBuilder.WithMetadata(new AllowAnonymousAttribute()); | ||
|
||
endpoints.MapRazorPages(); | ||
}); | ||
#endregion | ||
|
||
app.Services.UseMoryxConfigurations("Config"); | ||
app.Services.StartMoryxModules(); | ||
|
||
app.Run(); | ||
|
||
app.Services.StopMoryxModules(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.