From 985d464279926e28970090b64ea07397ae2fda09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=9F=B3=E5=A4=B4?= Date: Thu, 31 Oct 2024 09:51:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=98=9F=E5=B0=98=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E5=9F=BA=E7=A1=80=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E5=85=A5=EF=BC=8C=E4=BE=8B=E5=A6=82IConfigPr?= =?UTF-8?q?ovider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stardust.Extensions/StarFactoryExtensions.cs | 5 ++++- Stardust/StarHelper.cs | 5 +---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Stardust.Extensions/StarFactoryExtensions.cs b/Stardust.Extensions/StarFactoryExtensions.cs index d023376b..d86cfda8 100644 --- a/Stardust.Extensions/StarFactoryExtensions.cs +++ b/Stardust.Extensions/StarFactoryExtensions.cs @@ -49,7 +49,10 @@ public static StarFactory AddStardust(this IServiceCollection services, String? //services.Replace(new ServiceDescriptor(typeof(IConfigProvider), p => star.Config, ServiceLifetime.Singleton)); //var old = services.LastOrDefault(e => e.ServiceType == typeof(IConfigProvider))?.ImplementationInstance as IConfigProvider; //old ??= JsonConfigProvider.LoadAppSettings(); - services.Replace(new ServiceDescriptor(typeof(IConfigProvider), p => star.GetConfig()!, ServiceLifetime.Singleton)); + if (services.Any(e => e.ServiceType == typeof(IConfigProvider))) + services.Replace(new ServiceDescriptor(typeof(IConfigProvider), p => star.GetConfig()!, ServiceLifetime.Singleton)); + else + services.TryAddSingleton(p => star.GetConfig()!); // 分布式缓存 //services.Replace(new ServiceDescriptor(typeof(CacheService), p => new RedisCacheService(p), ServiceLifetime.Singleton)); diff --git a/Stardust/StarHelper.cs b/Stardust/StarHelper.cs index 2e5dc1ea..ebd72032 100644 --- a/Stardust/StarHelper.cs +++ b/Stardust/StarHelper.cs @@ -26,10 +26,7 @@ public static StarFactory AddStardust(this IObjectContainer services, String? se var old = JsonConfigProvider.LoadAppSettings(); star.SetLocalConfig(old); - if (services != ObjectContainer.Current && services is ObjectContainer container) - { - star.Register(services); - } + star.Register(services); return star; }