2024-07-29 22:32:26 +08:00
|
|
|
|
using AngleSharp;
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-06-21 22:59:30 +08:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2024-07-29 22:32:26 +08:00
|
|
|
|
using YaeBlog.Core.Abstractions;
|
2024-06-21 22:59:30 +08:00
|
|
|
|
using YaeBlog.Core.Models;
|
|
|
|
|
using YaeBlog.Core.Processors;
|
|
|
|
|
using YaeBlog.Core.Services;
|
|
|
|
|
|
|
|
|
|
namespace YaeBlog.Core.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class WebApplicationBuilderExtensions
|
|
|
|
|
{
|
|
|
|
|
public static WebApplicationBuilder AddYaeBlog(this WebApplicationBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.Services.Configure<BlogOptions>(builder.Configuration.GetSection(BlogOptions.OptionName));
|
|
|
|
|
|
|
|
|
|
builder.Services.AddHttpClient();
|
|
|
|
|
|
|
|
|
|
builder.Services.AddMarkdig();
|
|
|
|
|
builder.Services.AddYamlParser();
|
2024-07-29 22:32:26 +08:00
|
|
|
|
builder.Services.AddSingleton<IConfiguration>(_ => Configuration.Default);
|
2024-06-21 22:59:30 +08:00
|
|
|
|
builder.Services.AddSingleton<EssayScanService>();
|
|
|
|
|
builder.Services.AddSingleton<RendererService>();
|
|
|
|
|
builder.Services.AddSingleton<EssayContentService>();
|
2024-07-29 22:32:26 +08:00
|
|
|
|
builder.Services.AddSingleton<IEssayContentService, EssayContentService>(provider =>
|
|
|
|
|
provider.GetRequiredService<EssayContentService>());
|
|
|
|
|
builder.Services.AddSingleton<TableOfContentService>();
|
|
|
|
|
builder.Services.AddSingleton<ITableOfContentService, TableOfContentService>(provider =>
|
|
|
|
|
provider.GetRequiredService<TableOfContentService>());
|
2024-06-21 22:59:30 +08:00
|
|
|
|
builder.Services.AddTransient<ImagePostRenderProcessor>();
|
2024-07-29 22:32:26 +08:00
|
|
|
|
builder.Services.AddTransient<CodeBlockPostRenderProcessor>();
|
|
|
|
|
builder.Services.AddTransient<TablePostRenderProcessor>();
|
|
|
|
|
builder.Services.AddTransient<HeadlinePostRenderProcessor>();
|
2024-06-21 22:59:30 +08:00
|
|
|
|
builder.Services.AddTransient<BlogOptions>(provider =>
|
|
|
|
|
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
|
|
|
|
|
|
|
|
|
|
builder.Services.AddHostedService<BlogHostedService>();
|
|
|
|
|
|
|
|
|
|
return builder;
|
|
|
|
|
}
|
|
|
|
|
}
|