From 586ac256b1fa36eb341f26ec639a404bd3839d0b Mon Sep 17 00:00:00 2001 From: jackfiled Date: Sat, 20 Jan 2024 17:09:01 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E6=B7=BB=E5=8A=A0ProjectName=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YaeBlog.Core/Extensions/BlogApplicationExtension.cs | 4 ++-- YaeBlog.Core/Models/BlogOptions.cs | 6 +++--- YaeBlog.Core/Services/WebApplicationHostedService.cs | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/YaeBlog.Core/Extensions/BlogApplicationExtension.cs b/YaeBlog.Core/Extensions/BlogApplicationExtension.cs index 3b75ac6..38eff99 100644 --- a/YaeBlog.Core/Extensions/BlogApplicationExtension.cs +++ b/YaeBlog.Core/Extensions/BlogApplicationExtension.cs @@ -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", diff --git a/YaeBlog.Core/Models/BlogOptions.cs b/YaeBlog.Core/Models/BlogOptions.cs index 712cbe4..5313860 100644 --- a/YaeBlog.Core/Models/BlogOptions.cs +++ b/YaeBlog.Core/Models/BlogOptions.cs @@ -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; } } diff --git a/YaeBlog.Core/Services/WebApplicationHostedService.cs b/YaeBlog.Core/Services/WebApplicationHostedService.cs index 919804c..9293246 100644 --- a/YaeBlog.Core/Services/WebApplicationHostedService.cs +++ b/YaeBlog.Core/Services/WebApplicationHostedService.cs @@ -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(_ => provider.GetRequiredService()); + _websiteBuilder.Services.AddTransient(_ => + provider.GetRequiredService>().Value); }