|
|
|
@ -17,6 +17,7 @@ namespace HybirdFrameworkCore.Autofac
|
|
|
|
|
#region 带有接口层的服务注入
|
|
|
|
|
|
|
|
|
|
var repositoryDllFile = Path.Combine(basePath, "HybirdFrameworkRepository.dll");
|
|
|
|
|
var driverDllFile = Path.Combine(basePath, "HybirdFrameworkDriver.dll");
|
|
|
|
|
var servicesDllFile = Path.Combine(basePath, "HybirdFrameworkServices.dll");
|
|
|
|
|
|
|
|
|
|
if (!(File.Exists(servicesDllFile) && File.Exists(repositoryDllFile)))
|
|
|
|
@ -25,32 +26,21 @@ namespace HybirdFrameworkCore.Autofac
|
|
|
|
|
throw new Exception(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AOP 开关,如果想要打开指定的功能,只需要在 appsettigns.json 对应对应 true 就行。
|
|
|
|
|
//var cacheType = new List<Type>();
|
|
|
|
|
//if (AppSettingsConstVars.RedisConfigEnabled)
|
|
|
|
|
//{
|
|
|
|
|
// builder.RegisterType<RedisCacheAop>();
|
|
|
|
|
// cacheType.Add(typeof(RedisCacheAop));
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// builder.RegisterType<MemoryCacheAop>();
|
|
|
|
|
// cacheType.Add(typeof(MemoryCacheAop));
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// 获取 Service.dll 程序集服务,并注册
|
|
|
|
|
SplitInject(Assembly.LoadFrom(servicesDllFile), builder);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取 driver.dll 程序集服务,并注册
|
|
|
|
|
SplitInject(Assembly.LoadFrom(driverDllFile), builder);
|
|
|
|
|
// 获取 Repository.dll 程序集服务,并注册
|
|
|
|
|
SplitInject(Assembly.LoadFrom(repositoryDllFile), builder);
|
|
|
|
|
|
|
|
|
|
// 获取 Service.dll 程序集服务,并注册
|
|
|
|
|
SplitInject(Assembly.LoadFrom(servicesDllFile), builder);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SplitInject(Assembly assemblysServices, ContainerBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
List<Type> InstancePerLifetimeScopeList = new List<Type>();
|
|
|
|
|
List<Type> instancePerLifetimeScopeList = new List<Type>();
|
|
|
|
|
List<Type> instancePerDependencyList = new List<Type>();
|
|
|
|
|
List<Type> defaultList = new List<Type>();
|
|
|
|
|
foreach (var type in assemblysServices.ExportedTypes)
|
|
|
|
@ -60,21 +50,20 @@ namespace HybirdFrameworkCore.Autofac
|
|
|
|
|
{
|
|
|
|
|
if (ScopeConst.InstancePerLifetimeScope == scope.Scope)
|
|
|
|
|
{
|
|
|
|
|
InstancePerLifetimeScopeList.Add(type);
|
|
|
|
|
Log.Debug($"register InstancePerLifetimeScope {type}");
|
|
|
|
|
instancePerLifetimeScopeList.Add(type);
|
|
|
|
|
}
|
|
|
|
|
else if (ScopeConst.InstancePerDependency == scope.Scope)
|
|
|
|
|
{
|
|
|
|
|
Log.Debug($"register InstancePerDependency {type}");
|
|
|
|
|
instancePerDependencyList.Add(type);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Log.Debug($"register SingleInstance {type}");
|
|
|
|
|
defaultList.Add(type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
defaultList.Add(type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (defaultList.Count > 0)
|
|
|
|
@ -85,13 +74,46 @@ namespace HybirdFrameworkCore.Autofac
|
|
|
|
|
|
|
|
|
|
if (instancePerDependencyList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterTypes(instancePerDependencyList.ToArray()).InstancePerDependency()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); //支持属性注入依赖重复
|
|
|
|
|
foreach (Type type in instancePerDependencyList)
|
|
|
|
|
{
|
|
|
|
|
if (type.IsGenericType)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterGeneric(type).InstancePerDependency()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Type? iInterface = type.GetInterface("HybirdFrameworkDriver.ChargerServer.IMsgHandler");
|
|
|
|
|
if (iInterface != null)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterType(type).As(iInterface).InstancePerDependency()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iInterface = type.GetInterface("HybirdFrameworkDriver.ChargerServer.IDecoder");
|
|
|
|
|
if (iInterface != null)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterType(type).As(iInterface).InstancePerDependency()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iInterface = type.GetInterface("HybirdFrameworkDriver.ChargerServer.IEncoder");
|
|
|
|
|
if (iInterface != null)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterType(type).As(iInterface).InstancePerDependency()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.RegisterType(type).InstancePerDependency()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (InstancePerLifetimeScopeList.Count > 0)
|
|
|
|
|
if (instancePerLifetimeScopeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
builder.RegisterTypes(InstancePerLifetimeScopeList.ToArray()).InstancePerMatchingLifetimeScope()
|
|
|
|
|
builder.RegisterTypes(instancePerLifetimeScopeList.ToArray()).InstancePerMatchingLifetimeScope()
|
|
|
|
|
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); //支持属性注入依赖重复
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|