Created database

This commit is contained in:
t.ruspekhofer 2022-02-15 21:59:44 +01:00
parent e068536abe
commit eec8e419ba
19 changed files with 618 additions and 4 deletions

View file

@ -1,13 +1,21 @@
using Discord.OAuth2;
using Discord.OAuth2;
using Lieb.Data;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<LiebContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")));
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
builder.Services.AddServerSideBlazor();
builder.Services.AddAuthentication(opt =>
{
@ -33,7 +41,20 @@ if (!app.Environment.IsDevelopment())
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
else
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<LiebContext>();
context.Database.EnsureCreated();
DbInitializer.Initialize(context);
}
app.UseHttpsRedirection();