75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using Microsoft.IdentityModel.Tokens;
|
||
using System.Text;
|
||
using FaKrosnoEfDataModel;
|
||
using FaKrosnoEfDataModel.Services;
|
||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||
using SytelineSaAppEfDataModel;
|
||
using SytelineSaAppEfDataModel.Services;
|
||
using FaKrosnoMappingProfile = FaKrosnoEfDataModel.MappingProfile;
|
||
using SytelineSaAppMappingProfile = SytelineSaAppEfDataModel.MappingProfile;
|
||
|
||
var builder = WebApplication.CreateBuilder(args);
|
||
var configuration = builder.Configuration;
|
||
// Add services to the container.
|
||
builder.Services.AddDbContext<FaKrosnoDbContext>(options =>
|
||
options.UseSqlServer(builder.Configuration.GetConnectionString("FaKrosnoConnection")));
|
||
builder.Services.AddDbContext<SytelineSaAppDbContext>(options =>
|
||
options.UseSqlServer(builder.Configuration.GetConnectionString("SytelineSaAppConnection")));
|
||
|
||
builder.WebHost.UseUrls("http://*:5555");
|
||
|
||
builder.Services.AddControllers();
|
||
builder.Services.AddEndpointsApiExplorer();
|
||
builder.Services.AddEndpointsApiExplorer();
|
||
builder.Services.AddOpenApiDocument(config =>
|
||
{
|
||
config.Title = "FaKrosnoApi";
|
||
config.Version = "v1";
|
||
});
|
||
|
||
// Configure AutoMapper
|
||
builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile));
|
||
|
||
// 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<IScheduleOrderService, ScheduleOrderService>();
|
||
builder.Services.AddScoped<IScheduleOrderDetailsService, ScheduleOrderDetailsService>();
|
||
builder.Services.AddScoped<IEdiCustomerOrderService, EdiCustomerOrderService>();
|
||
builder.Services.AddScoped<IErrorLogService, ErrorLogService>();
|
||
builder.Services.AddScoped<ICustomerOrderService, CustomerOrderService>();
|
||
|
||
var app = builder.Build();
|
||
|
||
// Configure the HTTP request pipeline.
|
||
//if (app.Environment.IsDevelopment())
|
||
//{
|
||
app.UseOpenApi(); // Serwuje dokument OpenAPI
|
||
app.UseSwaggerUi(); // Dodaje interfejs u<>ytkownika Swagger
|
||
//}
|
||
|
||
app.UseHttpsRedirection();
|
||
|
||
app.UseAuthentication();
|
||
app.UseAuthorization();
|
||
|
||
app.MapControllers();
|
||
|
||
app.Run(); |