50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using MyDarling.Models;
|
|
using MyDarling.Services;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using MyDarling.Controllers;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddDbContext<DataContext>(opts =>
|
|
{
|
|
opts.UseSqlite(builder.Configuration["ConnectionStrings:MyDarlingDb"]);
|
|
opts.EnableSensitiveDataLogging(true);
|
|
});
|
|
|
|
builder.Services.AddDbContext<IdentityContext>(opts =>
|
|
{
|
|
opts.UseSqlite(builder.Configuration["ConnectionStrings:IdentityDb"]);
|
|
});
|
|
|
|
builder.Services.AddIdentity<IdentityUser, IdentityRole>()
|
|
.AddEntityFrameworkStores<IdentityContext>();
|
|
|
|
builder.Services.Configure<IdentityOptions>( opts =>
|
|
{
|
|
opts.Password.RequiredLength = 6;
|
|
opts.Password.RequireNonAlphanumeric = false;
|
|
opts.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyz";
|
|
});
|
|
|
|
builder.Services.AddTransient<IImageResizer, ImageResizer>();
|
|
builder.Services.AddScoped<IRobotsTxtGenerator, RobotsTxtGenerator>();
|
|
builder.Services.AddControllersWithViews();
|
|
builder.Services.AddRazorPages();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseStaticFiles();
|
|
app.MapControllers();
|
|
app.MapDefaultControllerRoute();
|
|
app.MapRazorPages();
|
|
|
|
var robotsScope = app.Services.CreateScope();
|
|
var robotsGenerator = robotsScope.ServiceProvider.GetService<IRobotsTxtGenerator>();
|
|
app.MapGet("/robots.txt", () => robotsGenerator!.GetRobotsText());
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
IdentitySeedData.CreateAdminAccount(app.Services, app.Configuration);
|
|
|
|
app.Run(); |