Web Api layout

This commit is contained in:
Jöran Malek 2024-02-07 22:16:59 +01:00
parent 5619093f41
commit da6d5576bf
32 changed files with 515 additions and 29 deletions

View file

@ -1,17 +1,31 @@
using Microsoft.AspNetCore.Identity;
using InkForge.Api.Data;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddHttpClient();
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<ApiDbcontext>()
.AddDefaultUI().AddDefaultTokenProviders();
var provider = builder.Configuration.GetValue<string>("DbProvider");
builder.Services.AddDbContext<ApiDbcontext>(options => _ = provider switch
{
"Sqlite" => options.UseSqlite(
builder.Configuration.GetConnectionString("AuthDb"),
x => x.MigrationsAssembly("InkForge.Api.Sqlite")
),
_ => throw new Exception($"Invalid Provider: {provider}")
});
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<ApiDbcontext>();
var app = builder.Build();
@ -23,11 +37,15 @@ if (app.Environment.IsDevelopment())
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapIdentityApi<IdentityUser>();
app.MapControllers();
app.MapRazorPages();
app.Run();