Mise à jour de 'EntityFramework_LoL/Sources/API_LoL_Project/Program.cs'
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
13bb701d1d
commit
8f150d8db0
@ -1,108 +1,108 @@
|
|||||||
using Business;
|
using Business;
|
||||||
using Entities;
|
using Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||||
using Model;
|
using Model;
|
||||||
using StubLib;
|
using StubLib;
|
||||||
using API_LoL_Project;
|
using API_LoL_Project;
|
||||||
using API_LoL_Project.JsonConverter;
|
using API_LoL_Project.JsonConverter;
|
||||||
using API_LoL_Project.Middleware.Auth;
|
using API_LoL_Project.Middleware.Auth;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
var connectionString = builder.Configuration.GetConnectionString("LolDatabase");
|
var connectionString = builder.Configuration.GetConnectionString("LolDatabase");
|
||||||
builder.Services.AddDbContext<LolDbContext>(options =>
|
builder.Services.AddDbContext<LolDbContext>(options =>
|
||||||
options.UseSqlite(connectionString), ServiceLifetime.Singleton);
|
options.UseSqlite(connectionString), ServiceLifetime.Singleton);
|
||||||
|
|
||||||
builder.Services.AddControllers().AddJsonOptions(options =>
|
builder.Services.AddControllers().AddJsonOptions(options =>
|
||||||
{
|
{
|
||||||
options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionaryConverter<string, int>());
|
options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionaryConverter<string, int>());
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen( cont =>
|
builder.Services.AddSwaggerGen( cont =>
|
||||||
{
|
{
|
||||||
cont.AddSecurityDefinition("ApiKey", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
cont.AddSecurityDefinition("ApiKey", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
|
||||||
{
|
{
|
||||||
Description = "The Key to acces to the API",
|
Description = "The Key to acces to the API",
|
||||||
Type = SecuritySchemeType.ApiKey,
|
Type = SecuritySchemeType.ApiKey,
|
||||||
Name = "x-api-key",
|
Name = "x-api-key",
|
||||||
In = ParameterLocation.Header,
|
In = ParameterLocation.Header,
|
||||||
Scheme = "ApiKeyScheme"
|
Scheme = "ApiKeyScheme"
|
||||||
});
|
});
|
||||||
|
|
||||||
var scheme = new OpenApiSecurityScheme
|
var scheme = new OpenApiSecurityScheme
|
||||||
{
|
{
|
||||||
Reference = new OpenApiReference
|
Reference = new OpenApiReference
|
||||||
{
|
{
|
||||||
Type = ReferenceType.SecurityScheme,
|
Type = ReferenceType.SecurityScheme,
|
||||||
Id = "ApiKey"
|
Id = "ApiKey"
|
||||||
},
|
},
|
||||||
In = ParameterLocation.Header
|
In = ParameterLocation.Header
|
||||||
};
|
};
|
||||||
|
|
||||||
var requirement = new OpenApiSecurityRequirement
|
var requirement = new OpenApiSecurityRequirement
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
scheme, new List<string>()
|
scheme, new List<string>()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
cont.AddSecurityRequirement(requirement);
|
cont.AddSecurityRequirement(requirement);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
builder.Services.AddApiVersioning(opt =>
|
builder.Services.AddApiVersioning(opt =>
|
||||||
{
|
{
|
||||||
opt.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);
|
opt.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(1, 0);
|
||||||
opt.AssumeDefaultVersionWhenUnspecified = true;
|
opt.AssumeDefaultVersionWhenUnspecified = true;
|
||||||
opt.ReportApiVersions = true;
|
opt.ReportApiVersions = true;
|
||||||
opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader());
|
opt.ApiVersionReader = ApiVersionReader.Combine(new UrlSegmentApiVersionReader());
|
||||||
});
|
});
|
||||||
builder.Services.ConfigureOptions<LolSwaggerOptions>();
|
builder.Services.ConfigureOptions<LolSwaggerOptions>();
|
||||||
builder.Services.AddVersionedApiExplorer(setup =>
|
builder.Services.AddVersionedApiExplorer(setup =>
|
||||||
{
|
{
|
||||||
setup.GroupNameFormat = "'v'VVV";
|
setup.GroupNameFormat = "'v'VVV";
|
||||||
setup.SubstituteApiVersionInUrl = true;
|
setup.SubstituteApiVersionInUrl = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddScoped<AuthMiddlewareFliter>();
|
builder.Services.AddScoped<AuthMiddlewareFliter>();
|
||||||
|
|
||||||
builder.Services.AddSingleton<IDataManager, DbData>();
|
builder.Services.AddSingleton<IDataManager, DbData>();
|
||||||
//builder.Services.AddSingleton<IDataManager, StubData>();
|
//builder.Services.AddSingleton<IDataManager, StubData>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
var apiVersionDescriptionProvider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();
|
var apiVersionDescriptionProvider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();
|
||||||
|
|
||||||
app?.Services?.GetService<LolDbContext>()?.Database.EnsureCreated();
|
app?.Services?.GetService<LolDbContext>()?.Database.EnsureCreated();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (true)
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
/* app.UseSwaggerUI();*/
|
/* app.UseSwaggerUI();*/
|
||||||
app.UseSwaggerUI(options =>
|
app.UseSwaggerUI(options =>
|
||||||
{
|
{
|
||||||
foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
|
foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
|
||||||
{
|
{
|
||||||
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
|
options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
|
||||||
description.GroupName.ToUpperInvariant());
|
description.GroupName.ToUpperInvariant());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
Loading…
Reference in new issue