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; }