add: 添加ProjectName配置选项
This commit is contained in:
parent
71b4549ce4
commit
586ac256b1
|
@ -10,9 +10,9 @@ using YamlDotNet.Serialization.NamingConventions;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Extensions;
|
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.json", optional: true, reloadOnChange: true);
|
||||||
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json",
|
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json",
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
using Microsoft.Extensions.Options;
|
namespace YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Models;
|
|
||||||
|
|
||||||
public class BlogOptions
|
public class BlogOptions
|
||||||
{
|
{
|
||||||
public const string OptionName = "Blog";
|
public const string OptionName = "Blog";
|
||||||
|
|
||||||
public required string Root { get; set; }
|
public required string Root { get; set; }
|
||||||
|
|
||||||
|
public required string ProjectName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using YaeBlog.Core.Models;
|
||||||
|
|
||||||
namespace YaeBlog.Core.Services;
|
namespace YaeBlog.Core.Services;
|
||||||
|
|
||||||
|
@ -74,6 +76,8 @@ public class WebApplicationHostedService : IHostedService
|
||||||
{
|
{
|
||||||
_websiteBuilder.Services.AddSingleton<EssayContentService>(_ =>
|
_websiteBuilder.Services.AddSingleton<EssayContentService>(_ =>
|
||||||
provider.GetRequiredService<EssayContentService>());
|
provider.GetRequiredService<EssayContentService>());
|
||||||
|
_websiteBuilder.Services.AddTransient<BlogOptions>(_ =>
|
||||||
|
provider.GetRequiredService<IOptions<BlogOptions>>().Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user