diff --git a/GFramework.Core/ioc/MicrosoftDiContainer.cs b/GFramework.Core/ioc/MicrosoftDiContainer.cs
index b1a0093..d588f6f 100644
--- a/GFramework.Core/ioc/MicrosoftDiContainer.cs
+++ b/GFramework.Core/ioc/MicrosoftDiContainer.cs
@@ -104,11 +104,23 @@ public class MicrosoftDiContainer(IServiceCollection? serviceCollection = null)
/// 服务接口或基类类型
/// 具体的实现类型
public void RegisterSingleton()
- where TImpl : class, TService where TService : class
+ where TImpl : class, TService
+ where TService : class
{
- Services.AddSingleton();
+ _lock.EnterWriteLock();
+ try
+ {
+ ThrowIfFrozen();
+ Services.AddSingleton();
+ _logger.Debug($"Singleton registered: {typeof(TService).Name}");
+ }
+ finally
+ {
+ _lock.ExitWriteLock();
+ }
}
+
///
/// 注册多个实例到其所有接口和具体类型
/// 实现一个实例支持多种接口类型的解析
@@ -234,12 +246,22 @@ public class MicrosoftDiContainer(IServiceCollection? serviceCollection = null)
///
/// 服务类型
/// 创建服务实例的工厂委托函数,接收IServiceProvider参数
- public void RegisterFactory(Func factory) where TService : class
+ public void RegisterFactory(
+ Func factory) where TService : class
{
- ThrowIfFrozen();
- Services.AddSingleton(factory);
+ _lock.EnterWriteLock();
+ try
+ {
+ ThrowIfFrozen();
+ Services.AddSingleton(factory);
+ }
+ finally
+ {
+ _lock.ExitWriteLock();
+ }
}
+
///
/// 注册中介行为管道
/// 用于配置Mediator框架的行为拦截和处理逻辑
@@ -269,9 +291,18 @@ public class MicrosoftDiContainer(IServiceCollection? serviceCollection = null)
/// 配置服务
///
/// 服务配置委托
- public void ExecuteServicesHook(Action? configurator = null)
+ public void ExecuteServicesHook(Action? configurator)
{
- configurator?.Invoke(Services);
+ _lock.EnterWriteLock();
+ try
+ {
+ ThrowIfFrozen();
+ configurator?.Invoke(Services);
+ }
+ finally
+ {
+ _lock.ExitWriteLock();
+ }
}
#endregion