first commit
This commit is contained in:
66
BookHive/Program.cs
Normal file
66
BookHive/Program.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using AutoMapper;
|
||||
using AutoMapper.EquivalencyExpression;
|
||||
using BookHive;
|
||||
using BookHive.MappingProfiles;
|
||||
using BookHive.Repositories;
|
||||
using FastEndpoints;
|
||||
using FastEndpoints.Security;
|
||||
using FastEndpoints.Swagger;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
|
||||
builder.Services
|
||||
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
|
||||
.AddAuthorization()
|
||||
.AddFastEndpoints()
|
||||
.AddCors(options =>
|
||||
{
|
||||
options.AddDefaultPolicy(policyBuilder =>
|
||||
{
|
||||
policyBuilder
|
||||
.WithOrigins("http://localhost:4200")
|
||||
.WithMethods("GET", "POST", "PUT", "DELETE", "PATCH")
|
||||
.AllowAnyHeader()
|
||||
.WithExposedHeaders(HeaderNames.ContentDisposition);
|
||||
});
|
||||
})
|
||||
.SwaggerDocument(options => { options.ShortSchemaNames = true; });
|
||||
|
||||
builder.Services.AddDbContext<BookHiveDbContext>();
|
||||
|
||||
builder.Services.AddScoped<AuthorRepository>();
|
||||
builder.Services.AddScoped<BookRepository>();
|
||||
builder.Services.AddScoped<MemberRepository>();
|
||||
builder.Services.AddScoped<ReviewRepository>();
|
||||
builder.Services.AddScoped<LoanRepository>();
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
MapperConfiguration mappingConfig = new(mc =>
|
||||
{
|
||||
mc.AddCollectionMappers();
|
||||
mc.AddProfile(new DtoToEntityMappings());
|
||||
mc.AddProfile(new EntityToDtoMappings());
|
||||
}, new LoggerFactory());
|
||||
|
||||
|
||||
AutoMapper.IMapper mapper = mappingConfig.CreateMapper();
|
||||
builder.Services.AddSingleton(mapper);
|
||||
|
||||
WebApplication app = builder.Build();
|
||||
app.UseAuthentication()
|
||||
.UseAuthorization()
|
||||
.UseFastEndpoints(options =>
|
||||
{
|
||||
options.Endpoints.ShortNames = true;
|
||||
options.Endpoints.RoutePrefix = "API";
|
||||
})
|
||||
.UseSwaggerGen();
|
||||
|
||||
// app.UseHttpsRedirection();
|
||||
|
||||
// app.UseCors();
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user