2024-01-17 13:20:32 +08:00
|
|
|
|
using Markdig;
|
2024-01-20 12:26:30 +08:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-01-17 13:20:32 +08:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using YaeBlog.Core.Builder;
|
|
|
|
|
using YaeBlog.Core.Models;
|
|
|
|
|
using YaeBlog.Core.Services;
|
2024-01-19 20:33:41 +08:00
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
2024-01-17 13:20:32 +08:00
|
|
|
|
|
|
|
|
|
namespace YaeBlog.Core.Extensions;
|
|
|
|
|
|
2024-01-20 17:09:01 +08:00
|
|
|
|
public static class BlogApplicationExtension
|
2024-01-17 13:20:32 +08:00
|
|
|
|
{
|
2024-01-20 17:09:01 +08:00
|
|
|
|
internal static void ConfigureBlogApplication(this BlogApplicationBuilder builder)
|
2024-01-17 13:20:32 +08:00
|
|
|
|
{
|
|
|
|
|
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
|
|
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json",
|
|
|
|
|
optional: true, reloadOnChange: true);
|
|
|
|
|
builder.Configuration.AddEnvironmentVariables();
|
|
|
|
|
|
|
|
|
|
builder.Services.Configure<BlogOptions>(
|
|
|
|
|
builder.Configuration.GetSection(BlogOptions.OptionName));
|
|
|
|
|
|
2024-01-19 20:33:41 +08:00
|
|
|
|
builder.YamlDeserializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
|
|
|
|
builder.YamlDeserializerBuilder.IgnoreUnmatchedProperties();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSingleton<MarkdownPipeline>(
|
|
|
|
|
_ => builder.MarkdigPipelineBuilder.Build());
|
|
|
|
|
builder.Services.AddSingleton<IDeserializer>(
|
|
|
|
|
_ => builder.YamlDeserializerBuilder.Build());
|
|
|
|
|
|
2024-01-17 13:20:32 +08:00
|
|
|
|
builder.Services.AddHostedService<BlogHostedService>();
|
|
|
|
|
builder.Services.AddSingleton<EssayScanService>();
|
|
|
|
|
builder.Services.AddSingleton<RendererService>();
|
|
|
|
|
builder.Services.AddSingleton<EssayContentService>();
|
2024-01-20 12:26:30 +08:00
|
|
|
|
}
|
2024-01-17 13:20:32 +08:00
|
|
|
|
|
2024-01-20 12:26:30 +08:00
|
|
|
|
public static void ConfigureWebApplication(this BlogApplicationBuilder builder,
|
|
|
|
|
Action<WebApplicationBuilder> configureWebApplicationBuilder,
|
|
|
|
|
Action<WebApplication> configureWebApplication)
|
|
|
|
|
{
|
|
|
|
|
builder.Services.AddHostedService<WebApplicationHostedService>(provider =>
|
|
|
|
|
new WebApplicationHostedService(configureWebApplicationBuilder,
|
|
|
|
|
configureWebApplication, provider));
|
2024-01-17 13:20:32 +08:00
|
|
|
|
}
|
|
|
|
|
}
|