using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using System.Text; using FaKrosnoApi.Models; using FaKrosnoApi.Services; using FaKrosnoEfDataModel; using FaKrosnoEfDataModel.Services; using Hangfire; using Hangfire.SqlServer; using Microsoft.AspNetCore.Authentication.JwtBearer; using OrdersManagementDataModel; using OrdersManagementDataModel.Services; using SytelineSaAppEfDataModel; using SytelineSaAppEfDataModel.Services; using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile; using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile; using OrdersManagementMappingProfile = OrdersManagementDataModel.MappingProfile; var builder = WebApplication.CreateBuilder(args); builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("FaKrosnoConnection"))); builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("SytelineSaAppConnection"))); builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("OrdersManagementConnection"))); builder.Services.Configure(builder.Configuration.GetSection("EmailSettings")); builder.Services.Configure(builder.Configuration.GetSection("JobSettings")); builder.WebHost.UseUrls("http://*:5001"); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddOpenApiDocument(config => { config.Title = "FaKrosnoApi"; config.Version = "v1"; }); // builder.Services.AddHangfire(config => config // .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) // .UseSimpleAssemblyNameTypeSerializer() // .UseRecommendedSerializerSettings() // .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions // { // CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), // SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), // QueuePollInterval = TimeSpan.Zero, // UseRecommendedIsolationLevel = true, // DisableGlobalLocks = true // })); // builder.Services.AddHangfireServer(); // Configure AutoMapper builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile), typeof(OrdersManagementMappingProfile)); // Configure JWT Authentication builder.Services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = builder.Configuration["Jwt:Issuer"], ValidAudience = builder.Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])) }; }); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); //builder.Services.AddHostedService(); var app = builder.Build(); app.UseOpenApi(); app.UseSwaggerUi(); app.UseHttpsRedirection(); app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); //app.UseHangfireDashboard(); // var scopeFactory = app.Services.GetRequiredService(); // using (var scope = scopeFactory.CreateScope()) // { // var scheduledJob = scope.ServiceProvider.GetRequiredService(); // scheduledJob.Start(); // } app.Run();