124 lines
5.0 KiB
C#
124 lines
5.0 KiB
C#
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 NSwag;
|
|
using NSwag.Generation.Processors.Security;
|
|
using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile;
|
|
using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile;
|
|
using OrdersManagementMappingProfile = OrdersManagementDataModel.MappingProfile;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddDbContext<FaKrosnoDbContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("FaKrosnoConnection")));
|
|
builder.Services.AddDbContext<SytelineSaAppDbContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("SytelineSaAppConnection")));
|
|
builder.Services.AddDbContext<OrdersManagementDbContext>(options =>
|
|
options.UseSqlServer(builder.Configuration.GetConnectionString("OrdersManagementConnection")));
|
|
|
|
builder.Services.Configure<EmailSettingsModel>(builder.Configuration.GetSection("EmailSettings"));
|
|
builder.Services.Configure<JobSettingsModel>(builder.Configuration.GetSection("JobSettings"));
|
|
|
|
builder.WebHost.UseUrls("http://*:5001");
|
|
|
|
// builder.Services.AddAuthentication(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"] ?? string.Empty)),
|
|
// NameClaimType = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
|
|
// };
|
|
// });
|
|
|
|
builder.Services.AddControllers();
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddOpenApiDocument(config =>
|
|
{
|
|
config.Title = "FaKrosnoApi";
|
|
config.Version = "v1";
|
|
|
|
config.AddSecurity("Bearer", new OpenApiSecurityScheme
|
|
{
|
|
Name = "Authorization",
|
|
Type = OpenApiSecuritySchemeType.Http,
|
|
Scheme = "Bearer",
|
|
BearerFormat = "JWT",
|
|
In = OpenApiSecurityApiKeyLocation.Header,
|
|
Description = "Wprowadź token JWT w formacie: Bearer {token}"
|
|
});
|
|
|
|
config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer"));
|
|
});
|
|
|
|
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();
|
|
|
|
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile),
|
|
typeof(OrdersManagementMappingProfile));
|
|
|
|
builder.Services.AddScoped<IScheduleOrderService, ScheduleOrderService>();
|
|
builder.Services.AddScoped<IScheduleOrderDetailsService, ScheduleOrderDetailsService>();
|
|
builder.Services.AddScoped<IEdiCustomerOrderService, EdiCustomerOrderService>();
|
|
builder.Services.AddScoped<IEdiCustomerOrderTranslateService, EdiCustomerOrderTranslateService>();
|
|
builder.Services.AddScoped<IErrorLogService, ErrorLogService>();
|
|
builder.Services.AddScoped<ICustomerOrderService, CustomerOrderService>();
|
|
builder.Services.AddScoped<IEmailService, EmailService>();
|
|
builder.Services.AddScoped<IScheduleJobService, ScheduleJobService>();
|
|
builder.Services.AddScoped<ITaskSchedulerService, TaskSchedulerService>();
|
|
builder.Services.AddScoped<IUserService, UserService>();
|
|
builder.Services.AddScoped<IRoleService, RoleService>();
|
|
builder.Services.AddScoped<IFunctionService, FunctionService>();
|
|
builder.Services.AddScoped<IUserRoleService, UserRoleService>();
|
|
builder.Services.AddScoped<IProductService, ProductService>();
|
|
builder.Services.AddScoped<IMaterialTransactionService, MaterialTransactionService>();
|
|
builder.Services.AddScoped<IWzClientService, WzClientService>();
|
|
builder.Services.AddScoped<IWzHeaderService, WzHeaderService>();
|
|
|
|
builder.Services.AddHostedService<TimedHostedService>();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseOpenApi();
|
|
app.UseSwaggerUi();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.UseHangfireDashboard();
|
|
|
|
app.Run();
|