Skip to content

Commit

Permalink
使用星尘时,优化基础类型的注入,例如IConfigProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 31, 2024
1 parent 848cbb9 commit 985d464
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Stardust.Extensions/StarFactoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 1 addition & 4 deletions Stardust/StarHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 985d464

Please sign in to comment.