add: 添加ProjectName配置选项

This commit is contained in:
jackfiled 2024-01-20 17:09:01 +08:00
parent 71b4549ce4
commit 586ac256b1
3 changed files with 9 additions and 5 deletions

View File

@ -10,9 +10,9 @@ using YamlDotNet.Serialization.NamingConventions;
namespace YaeBlog.Core.Extensions;
internal static class BlogApplicationExtension
public static class BlogApplicationExtension
{
public static void ConfigureBlogApplication(this BlogApplicationBuilder builder)
internal static void ConfigureBlogApplication(this BlogApplicationBuilder builder)
{
builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json",

View File

@ -1,10 +1,10 @@
using Microsoft.Extensions.Options;
namespace YaeBlog.Core.Models;
namespace YaeBlog.Core.Models;
public class BlogOptions
{
public const string OptionName = "Blog";
public required string Root { get; set; }
public required string ProjectName { get; set; }
}

View File

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using YaeBlog.Core.Models;
namespace YaeBlog.Core.Services;
@ -74,6 +76,8 @@ public class WebApplicationHostedService : IHostedService
{
_websiteBuilder.Services.AddSingleton<EssayContentService>(_ =>
provider.GetRequiredService<EssayContentService>());
_websiteBuilder.Services.AddTransient<BlogOptions>(_ =>
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
}