YaeBlog/YaeBlog.Core/Extensions/BlogApplicationExtension.cs

40 lines
1.5 KiB
C#
Raw Normal View History

2024-01-17 13:20:32 +08:00
using Markdig;
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;
internal static class BlogApplicationExtension
{
public static BlogApplicationBuilder ConfigureBlogApplication(this BlogApplicationBuilder builder)
{
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>();
return builder;
}
}