Skip to content

Commit

Permalink
Merge pull request #19 from PHOENIXCONTACT/migrate/remove-startup
Browse files Browse the repository at this point in the history
Remove Startup.cs
  • Loading branch information
Toxantron authored Dec 7, 2023
2 parents b8baef8 + 55d608a commit dfe6cc6
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 154 deletions.
27 changes: 27 additions & 0 deletions src/MyApplication.App/ExamplePolicyProvider.cs
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;
}
}

}
123 changes: 95 additions & 28 deletions src/MyApplication.App/Program.cs
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();
2 changes: 1 addition & 1 deletion src/MyApplication.App/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:60572;http://localhost:60573"
"applicationUrl": "https://localhost:5000"
}
}
}
125 changes: 0 additions & 125 deletions src/MyApplication.App/Startup.cs

This file was deleted.

0 comments on commit dfe6cc6

Please sign in to comment.