YaeBlog/YaeBlog.Core/Builder/BlogApplicationBuilder.cs

56 lines
1.9 KiB
C#
Raw Normal View History

2024-01-16 20:33:39 +08:00
using Markdig;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.Metrics;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using YaeBlog.Core.Extensions;
2024-01-19 20:33:41 +08:00
using YamlDotNet.Serialization;
2024-01-16 20:33:39 +08:00
namespace YaeBlog.Core.Builder;
public sealed class BlogApplicationBuilder : IHostApplicationBuilder
{
private readonly HostApplicationBuilder _hostApplicationBuilder;
2024-01-19 20:33:41 +08:00
public MarkdownPipelineBuilder MarkdigPipelineBuilder { get; }
public DeserializerBuilder YamlDeserializerBuilder { get; }
2024-01-16 20:33:39 +08:00
internal BlogApplicationBuilder(BlogApplicationOptions options)
{
ConfigurationManager configuration = new();
MarkdigPipelineBuilder = new MarkdownPipelineBuilder();
2024-01-19 20:33:41 +08:00
YamlDeserializerBuilder = new DeserializerBuilder();
2024-01-16 20:33:39 +08:00
_hostApplicationBuilder = new HostApplicationBuilder(new HostApplicationBuilderSettings
{
Args = options.Args, Configuration = configuration
});
}
public BlogApplication Build()
{
this.ConfigureBlogApplication();
return new BlogApplication(_hostApplicationBuilder.Build());
}
public void ConfigureContainer<TContainerBuilder>(
IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null)
where TContainerBuilder : notnull
=> _hostApplicationBuilder.ConfigureContainer(factory, configure);
public IDictionary<object, object> Properties
=> (_hostApplicationBuilder as IHostApplicationBuilder).Properties;
public IHostEnvironment Environment => _hostApplicationBuilder.Environment;
public IConfigurationManager Configuration => _hostApplicationBuilder.Configuration;
public ILoggingBuilder Logging => _hostApplicationBuilder.Logging;
public IMetricsBuilder Metrics => _hostApplicationBuilder.Metrics;
public IServiceCollection Services => _hostApplicationBuilder.Services;
}