12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using MTWorkHR.Application;
- using MTWorkHR.Infrastructure;
- using MTWorkHR.Identity;
- using Microsoft.Extensions.Configuration;
- using MTWorkHR.Infrastructure.Data;
- 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;
- 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.AddInfrastructureServices(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();
|