AppServer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using WebTemplate.ServerAspects.Auth;
  2. using WebTemplate.ServerAspects.Controllers;
  3. using WebTemplate.ServerAspects.Cors;
  4. using WebTemplate.ServerAspects.Json;
  5. using WebTemplate.ServerAspects.Spa;
  6. using WebTemplate.ServerAspects.Swagger;
  7. using WebTemplate.Status;
  8. namespace WebTemplate;
  9. public class AppServer
  10. {
  11. private readonly IList<IAppConfigurationModule> _modules = new List<IAppConfigurationModule>
  12. {
  13. new JsonModule(),
  14. new AuthModule(),
  15. new CorsModule(),
  16. new SpaRoutingModule(),
  17. new SwaggerModule(),
  18. new StatusEndpointModule(),
  19. new ControllersModule(),
  20. };
  21. public void Start(string[] args)
  22. {
  23. var builder = WebApplication.CreateBuilder(args);
  24. SetupConfiguration(builder.Configuration, builder.Environment);
  25. foreach (var appConfigurationModule in _modules)
  26. {
  27. appConfigurationModule.ConfigureServices(builder.Services, builder.Configuration);
  28. }
  29. var app = builder.Build();
  30. app.UseHttpsRedirection();
  31. foreach (var appConfigurationModule in _modules)
  32. {
  33. appConfigurationModule.ConfigureApplication(app);
  34. }
  35. app.Run();
  36. }
  37. private void SetupConfiguration(ConfigurationManager configuration, IWebHostEnvironment env)
  38. {
  39. configuration.AddJsonFile($"~/{env.ApplicationName}.json", optional: true);
  40. }
  41. }