refactor: 设置默认Builder配置函数和Application配置函数

新增修改BlogEssay工具函数
This commit is contained in:
jackfiled 2024-01-25 11:41:54 +08:00
parent 5f8db267d9
commit 9d68c675cf
4 changed files with 26 additions and 3 deletions

View File

@ -31,8 +31,10 @@ public sealed class BlogApplicationBuilder : IHostApplicationBuilder
public BlogApplication Build()
{
this.ConfigureBlogApplication();
return new BlogApplication(_hostApplicationBuilder.Build());
this.ConfigureDefaultBlogApplicationBuilder();
BlogApplication application = new(_hostApplicationBuilder.Build());
application.ConfigureDefaultBlogApplication();
return application;
}
public void ConfigureContainer<TContainerBuilder>(

View File

@ -12,7 +12,7 @@ namespace YaeBlog.Core.Extensions;
public static class BlogApplicationBuilderExtension
{
internal static void ConfigureBlogApplication(this BlogApplicationBuilder builder)
internal static void ConfigureDefaultBlogApplicationBuilder(this BlogApplicationBuilder builder)
{
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json",

View File

@ -7,6 +7,11 @@ namespace YaeBlog.Core.Extensions;
public static class BlogApplicationExtension
{
internal static void ConfigureDefaultBlogApplication(this BlogApplication application)
{
}
public static void UsePreRenderProcessor<T>(this BlogApplication application)
where T : IPreRenderProcessor
{

View File

@ -16,6 +16,22 @@ public class BlogEssay
public required string HtmlContent { get; init; }
public BlogEssay WithNewHtmlContent(string newHtmlContent)
{
var essay = new BlogEssay
{
Title = Title,
FileName = FileName,
PublishTime = PublishTime,
Description = Description,
WordCount = WordCount,
HtmlContent = newHtmlContent
};
essay.Tags.AddRange(Tags);
return essay;
}
public override string ToString()
{
return $"{Title}-{PublishTime}";