YaeBlog/YaeBlog.Core/Extensions/WebApplicationBuilderExtensions.cs

43 lines
1.8 KiB
C#
Raw Normal View History

2024-07-29 21:52:23 +08:00
using AngleSharp;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
2024-07-27 21:07:57 +08:00
using YaeBlog.Core.Abstractions;
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 21:52:23 +08:00
builder.Services.AddSingleton<IConfiguration>(_ => Configuration.Default);
builder.Services.AddSingleton<EssayScanService>();
builder.Services.AddSingleton<RendererService>();
builder.Services.AddSingleton<EssayContentService>();
2024-07-27 21:07:57 +08:00
builder.Services.AddSingleton<IEssayContentService, EssayContentService>(provider =>
provider.GetRequiredService<EssayContentService>());
2024-07-29 21:52:23 +08:00
builder.Services.AddSingleton<TableOfContentService>();
builder.Services.AddSingleton<ITableOfContentService, TableOfContentService>(provider =>
provider.GetRequiredService<TableOfContentService>());
builder.Services.AddTransient<ImagePostRenderProcessor>();
2024-07-28 11:43:58 +08:00
builder.Services.AddTransient<CodeBlockPostRenderProcessor>();
builder.Services.AddTransient<TablePostRenderProcessor>();
2024-07-29 21:52:23 +08:00
builder.Services.AddTransient<HeadlinePostRenderProcessor>();
builder.Services.AddTransient<BlogOptions>(provider =>
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
builder.Services.AddHostedService<BlogHostedService>();
return builder;
}
}