2024-01-23 20:37:41 +08:00
|
|
|
|
using Markdig;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using YaeBlog.Core.Builder;
|
|
|
|
|
using YaeBlog.Core.Models;
|
2024-01-25 17:33:46 +08:00
|
|
|
|
using YaeBlog.Core.Processors;
|
2024-01-23 20:37:41 +08:00
|
|
|
|
using YaeBlog.Core.Services;
|
|
|
|
|
using YamlDotNet.Serialization;
|
|
|
|
|
using YamlDotNet.Serialization.NamingConventions;
|
|
|
|
|
|
|
|
|
|
namespace YaeBlog.Core.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class BlogApplicationBuilderExtension
|
|
|
|
|
{
|
2024-01-25 11:41:54 +08:00
|
|
|
|
internal static void ConfigureDefaultBlogApplicationBuilder(this BlogApplicationBuilder builder)
|
2024-01-23 20:37:41 +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));
|
|
|
|
|
|
|
|
|
|
builder.YamlDeserializerBuilder.WithNamingConvention(CamelCaseNamingConvention.Instance);
|
|
|
|
|
builder.YamlDeserializerBuilder.IgnoreUnmatchedProperties();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSingleton<MarkdownPipeline>(
|
|
|
|
|
_ => builder.MarkdigPipelineBuilder.Build());
|
|
|
|
|
builder.Services.AddSingleton<IDeserializer>(
|
|
|
|
|
_ => builder.YamlDeserializerBuilder.Build());
|
|
|
|
|
|
|
|
|
|
builder.Services.AddHostedService<BlogHostedService>();
|
|
|
|
|
builder.Services.AddSingleton<EssayScanService>();
|
|
|
|
|
builder.Services.AddSingleton<RendererService>();
|
|
|
|
|
builder.Services.AddSingleton<EssayContentService>();
|
2024-01-25 15:55:09 +08:00
|
|
|
|
|
2024-01-25 17:33:46 +08:00
|
|
|
|
// 设置图像处理器
|
|
|
|
|
builder.Services.AddSingleton<ImagePostRenderProcessor>();
|
|
|
|
|
ImagePostRenderProcessor.AddImageApiEndpoint(builder);
|
|
|
|
|
|
2024-01-25 15:55:09 +08:00
|
|
|
|
builder.Services.AddHostedService<WebApplicationHostedService>((provider)
|
|
|
|
|
=> new WebApplicationHostedService(builder.WebApplicationBuilderConfigurations,
|
|
|
|
|
builder.WebApplicationConfigurations, provider));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ConfigureWebApplicationBuilder(this BlogApplicationBuilder builder,
|
|
|
|
|
Action<WebApplicationBuilder> configureWebApplicationBuilder)
|
|
|
|
|
{
|
|
|
|
|
builder.WebApplicationBuilderConfigurations.Add(configureWebApplicationBuilder);
|
2024-01-23 20:37:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ConfigureWebApplication(this BlogApplicationBuilder builder,
|
|
|
|
|
Action<WebApplication> configureWebApplication)
|
|
|
|
|
{
|
2024-01-25 15:55:09 +08:00
|
|
|
|
builder.WebApplicationConfigurations.Add(configureWebApplication);
|
2024-01-23 20:37:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|