oliverbooth.dev/OliverBooth/Program.cs

55 lines
1.7 KiB
C#
Raw Normal View History

2023-08-08 00:34:15 +01:00
using Markdig;
2023-08-06 15:56:08 +01:00
using NLog.Extensions.Logging;
using OliverBooth.Data;
using OliverBooth.Markdown;
using OliverBooth.Markdown.Timestamp;
using OliverBooth.Middleware;
2023-08-06 15:56:08 +01:00
using OliverBooth.Services;
using X10D.Hosting.DependencyInjection;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddTomlFile("data/config.toml", true, true);
2023-05-26 19:05:44 +01:00
2023-08-06 15:56:08 +01:00
builder.Logging.ClearProviders();
builder.Logging.AddNLog();
builder.Services.AddHostedSingleton<LoggingService>();
builder.Services.AddSingleton<ConfigurationService>();
builder.Services.AddSingleton<TemplateService>();
builder.Services.AddSingleton(provider => new MarkdownPipelineBuilder()
.Use<TimestampExtension>()
2023-08-09 23:19:19 +01:00
.Use(new TemplateExtension(provider.GetRequiredService<TemplateService>()))
2023-08-08 00:34:15 +01:00
.UseAdvancedExtensions()
.UseBootstrap()
2023-08-09 23:19:39 +01:00
.UseEmojiAndSmiley()
2023-08-09 23:19:29 +01:00
.UseSmartyPants()
2023-08-08 00:34:15 +01:00
.Build());
2023-08-06 15:56:08 +01:00
builder.Services.AddDbContextFactory<BlogContext>();
builder.Services.AddDbContextFactory<WebContext>();
builder.Services.AddSingleton<BlogService>();
2023-08-06 15:55:12 +01:00
builder.Services.AddRazorPages().AddRazorRuntimeCompilation();
2023-08-05 21:01:47 +01:00
builder.Services.AddControllersWithViews();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
2023-05-26 19:05:44 +01:00
WebApplication app = builder.Build();
2023-05-26 19:05:44 +01:00
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
2023-08-05 20:58:03 +01:00
2023-08-05 21:01:47 +01:00
app.MapControllers();
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
2023-05-26 19:05:44 +01:00
app.MapRazorPages();
app.MapRssFeed("/blog/feed");
2023-05-26 19:05:44 +01:00
app.Run();