No Description

Startup.cs 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using Backend.Data;
  2. using Backend.Data.Config;
  3. using Backend.Data.Interfaces;
  4. using Backend.Data.Repositories;
  5. using Backend.Services;
  6. using Backend.Services.Interface;
  7. using Backend.Services.Mapper;
  8. using Mediator;
  9. using MediatR;
  10. using Microsoft.AspNetCore.Builder;
  11. using Microsoft.AspNetCore.Hosting;
  12. using Microsoft.AspNetCore.Http;
  13. using Microsoft.AspNetCore.Mvc;
  14. using Microsoft.Extensions.Configuration;
  15. using Microsoft.Extensions.DependencyInjection;
  16. using Microsoft.Extensions.DependencyInjection.Extensions;
  17. using Microsoft.Extensions.Hosting;
  18. using Microsoft.Extensions.Logging;
  19. using Microsoft.OpenApi.Models;
  20. using System;
  21. using System.Reflection;
  22. using System.Threading.Tasks;
  23. namespace Backend.API
  24. {
  25. public class Startup
  26. {
  27. private readonly IConfiguration _configuration = null;
  28. private readonly IHostEnvironment _appEnvironment = null;
  29. public Startup(IConfiguration configuration, IHostEnvironment appEnvironment)
  30. {
  31. _configuration = configuration;
  32. _appEnvironment = appEnvironment;
  33. }
  34. // This method gets called by the runtime. Use this method to add services to the container.
  35. public void ConfigureServices(IServiceCollection services)
  36. {
  37. services.AddControllers();
  38. services.AddOptions();
  39. AddDataDependencyInjectionService(services);
  40. AddDataDependencyInjectionRepository(services);
  41. AddDatabase(services);
  42. AddMediaRHandlerDependency(services);
  43. services.AddAutoMapper(typeof(AutoMapperProfile));
  44. services.AddSwaggerGen(c =>
  45. {
  46. c.SwaggerDoc("v2", new OpenApiInfo { Title = "Catalogue.Backend.API", Version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion });
  47. });
  48. }
  49. private static void AddDataDependencyInjectionService(IServiceCollection services)
  50. {
  51. services.AddScoped<ITypeProprieteService, TypeProprieteService>();
  52. services.AddScoped<IProprieteService, ProprieteService>();
  53. services.AddScoped<IProduitService, ProduitService>();
  54. services.AddScoped<ICommandeService, CommandeService>();
  55. services.AddScoped<ILigneCommandeService, LigneCommandeService>();
  56. services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
  57. }
  58. private static void AddMediaRHandlerDependency(IServiceCollection services)
  59. {
  60. services.AddMediatR(Assembly.GetExecutingAssembly());
  61. services.AddMediatR(typeof(GetTypeProprieteListHandler).Assembly);
  62. services.AddMediatR(typeof(AddTypeProprieteHandler).Assembly);
  63. services.AddMediatR(typeof(RemoveTypeProprieteHandler).Assembly);
  64. services.AddMediatR(typeof(GetProprieteListHandler).Assembly);
  65. services.AddMediatR(typeof(AddProprieteHandler).Assembly);
  66. services.AddMediatR(typeof(RemoveProprieteHandler).Assembly);
  67. services.AddMediatR(typeof(GetProduitListHandler).Assembly);
  68. services.AddMediatR(typeof(AddProduitHandler).Assembly);
  69. services.AddMediatR(typeof(RemoveProduitHandler).Assembly);
  70. services.AddMediatR(typeof(GetCommandeListHandler).Assembly);
  71. services.AddMediatR(typeof(AddCommandeHandler).Assembly);
  72. services.AddMediatR(typeof(RemoveCommandeHandler).Assembly);
  73. services.AddMediatR(typeof(GetLigneCommandeListHandler).Assembly);
  74. services.AddMediatR(typeof(AddLigneCommandeHandler).Assembly);
  75. services.AddMediatR(typeof(RemoveLigneCommandeHandler).Assembly);
  76. }
  77. private static void AddDataDependencyInjectionRepository(IServiceCollection services)
  78. {
  79. services.AddScoped<IApplicationDatabaseContext, ApplicationDatabaseContext>();
  80. services.AddScoped<ICommandeRepository, CommandeRepository>();
  81. services.AddScoped<ILigneCommandeRepository, LigneCommandeRepository>();
  82. services.AddScoped<IProduitRepository, ProduitRepository>();
  83. services.AddScoped<IProprieteRepository, ProprieteRepository>();
  84. services.AddScoped<ITypeProprieteRepository, TypeProprieteRepository>();
  85. }
  86. protected virtual void AddDatabase(IServiceCollection services)
  87. {
  88. if (services != null)
  89. {
  90. services.AddDatabaseModule(_configuration);
  91. }
  92. }
  93. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  94. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
  95. {
  96. if (env.IsDevelopment())
  97. {
  98. app.UseDeveloperExceptionPage();
  99. }
  100. app.UseRouting();
  101. app.UseAuthorization();
  102. app.UseEndpoints(endpoints =>
  103. {
  104. endpoints.MapControllers();
  105. });
  106. app.UseApplicationDatabase(serviceProvider);
  107. app.UseSwagger();
  108. app.UseSwaggerUI(c => {
  109. c.SwaggerEndpoint("/swagger/v2/swagger.json", "Catalogue.Backend.API");
  110. });
  111. }
  112. }
  113. }

Powered by TurnKey Linux.