1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using MTWorkHR.Application;
- using MTWorkHR.Infrastructure;
- using Microsoft.EntityFrameworkCore;
- using MTWorkHR.Core;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Application.Middlewares;
- using MTWorkHR.Application.Services.Interfaces;
- using MTWorkHR.Application.Filters;
- using MTWorkHR.Application.StartupService;
- using Microsoft.AspNetCore.Mvc;
- using MTWorkHR.Infrastructure.DBContext;
- var builder = WebApplication.CreateBuilder(args);
- // Add services to the container.
- builder.Services.AddDbContext<HRDataContext>(options =>
- {
- options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
- });
- var config = new AppSettingsConfiguration();
- builder.Configuration.Bind(config);
- builder.Services.AddApplicationServices(config);
- builder.Services.AddInfrastructureIdentityServices(config);
- //builder.Services.AddPersistenceServices(builder.Configuration);
- //builder.Services.AddIdentityServices(config);
- builder.Services.AddHostedService<DbMigrationService>();
- //builder.Services.AddControllers();
- builder.Services.AddControllers(options =>
- {
- //add filter by instance
- options.Filters.Add(new InputValidationActionFilter());
- //add filter By the type
- options.Filters.Add(typeof(InputValidationActionFilter));
- });
- //disable default model validation, because we handle this in InputValidationActionFilter and LoggingMiddleware.
- builder.Services.Configure<ApiBehaviorOptions>(options =>
- {
- options.SuppressModelStateInvalidFilter = true;
- });
- // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
- builder.Services.AddEndpointsApiExplorer();
- builder.Services.AddSwaggerGen();
- var app = builder.Build();
- // Configure the HTTP request pipeline.
- // if (app.Environment.IsDevelopment())
- // {
- app.UseSwagger();
- app.UseSwaggerUI();
- // }
- app.UseHttpsRedirection();
- app.UseAuthentication();
- app.UseAuthorization();
- app.UseMiddleware<LoggingMiddleware>();
- app.MapControllers();
- app.Run();
|