Program.cs 2.0 KB

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