Program.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using MTWorkHR.Application;
  2. using MTWorkHR.Infrastructure;
  3. using Microsoft.EntityFrameworkCore;
  4. using MTWorkHR.Core;
  5. using MTWorkHR.Core.Global;
  6. using MTWorkHR.Application.Middlewares;
  7. using MTWorkHR.Application.Services.Interfaces;
  8. using MTWorkHR.Application.Filters;
  9. using MTWorkHR.Application.StartupService;
  10. using Microsoft.AspNetCore.Mvc;
  11. using MTWorkHR.Infrastructure.DBContext;
  12. var builder = WebApplication.CreateBuilder(args);
  13. // Add services to the container.
  14. builder.Services.AddDbContext<HRDataContext>(options =>
  15. {
  16. options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
  17. });
  18. var config = new AppSettingsConfiguration();
  19. builder.Configuration.Bind(config);
  20. builder.Services.AddApplicationServices(config);
  21. builder.Services.AddInfrastructureIdentityServices(config);
  22. //builder.Services.AddPersistenceServices(builder.Configuration);
  23. //builder.Services.AddIdentityServices(config);
  24. builder.Services.AddHostedService<DbMigrationService>();
  25. //builder.Services.AddControllers();
  26. builder.Services.AddControllers(options =>
  27. {
  28. //add filter by instance
  29. options.Filters.Add(new InputValidationActionFilter());
  30. //add filter By the type
  31. options.Filters.Add(typeof(InputValidationActionFilter));
  32. });
  33. //disable default model validation, because we handle this in InputValidationActionFilter and LoggingMiddleware.
  34. builder.Services.Configure<ApiBehaviorOptions>(options =>
  35. {
  36. options.SuppressModelStateInvalidFilter = true;
  37. });
  38. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  39. builder.Services.AddEndpointsApiExplorer();
  40. builder.Services.AddSwaggerGen();
  41. var app = builder.Build();
  42. // Configure the HTTP request pipeline.
  43. // if (app.Environment.IsDevelopment())
  44. // {
  45. app.UseSwagger();
  46. app.UseSwaggerUI();
  47. // }
  48. app.UseHttpsRedirection();
  49. app.UseAuthentication();
  50. app.UseAuthorization();
  51. app.UseMiddleware<LoggingMiddleware>();
  52. app.MapControllers();
  53. app.Run();