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