123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.OpenApi.Models;
- using MTWorkHR.API.Swagger;
- using Azure.Storage.Blobs;
- using Moq;
- using Microsoft.Extensions.DependencyInjection;
- using DevExpress.AspNetCore;
- using DevExpress.XtraCharts;
- using DevExpress.XtraReports.Web.Extensions;
- using DevExpress.AspNetCore.Reporting;
- using MTWorkHR.Infrastructure.Reports;
- using MTWorkHR.API.Chat;
- using Microsoft.AspNetCore.SignalR;
- using MTWorkHR.Application.Services.Payment;
- var builder = WebApplication.CreateBuilder(args);
- if (OperatingSystem.IsLinux())
- {
- builder.Configuration.AddJsonFile("appsettings.Linux.json", optional: true, reloadOnChange: true);
- }
- var config = new AppSettingsConfiguration();
- builder.Services.AddDbContext<HRDataContext>(options =>
- {
- options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
-
- });
- builder.Configuration.Bind(config);
- builder.Services.AddApplicationServices(config);
- builder.Services.AddInfrastructureIdentityServices(config);
- builder.Services.AddHostedService<DbMigrationService>();
- if (builder.Environment.IsDevelopment())
- {
- var mockBlobServiceClient = new Mock<BlobServiceClient>();
-
- var mockBlobContainerClient = new Mock<BlobContainerClient>();
-
- mockBlobServiceClient
- .Setup(x => x.GetBlobContainerClient(It.IsAny<string>()))
- .Returns(mockBlobContainerClient.Object);
- builder.Services.AddSingleton(mockBlobServiceClient.Object);
- }
- else
- {
-
- builder.Services.AddSingleton(x => new BlobServiceClient(config.ConnectionStrings.BlobConnectionString));
- }
- builder.Services.AddControllers(options =>
- {
-
- options.Filters.Add(new InputValidationActionFilter());
-
- options.Filters.Add(typeof(InputValidationActionFilter));
- });
- builder.Services.Configure<ApiBehaviorOptions>(options =>
- {
- options.SuppressModelStateInvalidFilter = true;
- });
- builder.Services.AddDevExpressControls();
- builder.Services.AddSingleton<MatchMoveService>();
- builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>();
- builder.Services.ConfigureReportingServices(configurator => {
- configurator.ConfigureWebDocumentViewer(viewerConfigurator => {
- viewerConfigurator.UseCachedReportSourceBuilder();
- });
- });
- builder.Services.AddEndpointsApiExplorer();
- builder.Services.AddSignalR(options =>
- {
- options.EnableDetailedErrors = true;
- });
- builder.Services.AddCors(options => {
- options.AddPolicy("CORSPolicy", builder => builder.AllowAnyMethod().AllowAnyHeader().AllowCredentials().SetIsOriginAllowed((hosts) => true));
- });
- builder.Services.AddSwaggerGen(swagger =>
- {
-
- swagger.OperationFilter<HeaderOperationFilter>();
-
- swagger.SchemaFilter<EnumSchemaFilter>();
-
- swagger.SwaggerDoc("v1", new OpenApiInfo
- {
- Version = "v1",
- Title = "MTWorkHR.API",
- Description = "MTWorkHR.APIDesc"
- });
- swagger.CustomOperationIds(
- d => (d.ActionDescriptor as ControllerActionDescriptor)?.ControllerName + (d.ActionDescriptor as ControllerActionDescriptor)?.ActionName
- );
-
- swagger.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
- {
- Name = "Authorization",
- Type = SecuritySchemeType.ApiKey,
- Scheme = "Bearer",
- BearerFormat = "JWT",
- In = ParameterLocation.Header,
- Description = "Enter 'Bearer' [space] and then your valid token in the text input below.\r\n\r\nExample: \"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9\"",
- });
- swagger.AddSecurityRequirement(new OpenApiSecurityRequirement
- {
- {
- new OpenApiSecurityScheme
- {
- Reference = new OpenApiReference
- {
- Type = ReferenceType.SecurityScheme,
- Id = "Bearer"
- }
- },
- new string[] {}
- }
- });
- });
- builder.Services.AddAuthorization(options =>
- {
- options.AddPolicy("SuperAdminOnly", policy => policy.RequireRole("Admin"));
- });
- var app = builder.Build();
- app.UseDevExpressControls();
- app.UseSwagger();
- app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MTWorkHR.API v1"));
- app.UseRouting();
- app.UseMiddleware<LoggingMiddleware>();
- app.UseCors("CORSPolicy");
- app.UseHttpsRedirection();
- app.UseAuthentication();
- app.UseAuthorization();
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapHub<ChatHub>("/chatHub");
- });
- app.MapControllers();
- app.Run();
|