@@ -20,8 +20,9 @@ public void ConfigureComponent(Type concreteComponent, DependencyLifecycle depen
20
20
return ;
21
21
}
22
22
23
- serviceCollection . Add ( new ServiceDescriptor ( concreteComponent , concreteComponent , Map ( dependencyLifecycle ) ) ) ;
24
- RegisterInterfaces ( concreteComponent ) ;
23
+ var serviceLifetime = Map ( dependencyLifecycle ) ;
24
+ serviceCollection . Add ( new ServiceDescriptor ( concreteComponent , concreteComponent , serviceLifetime ) ) ;
25
+ RegisterInterfaces ( concreteComponent , serviceLifetime ) ;
25
26
}
26
27
27
28
public void ConfigureComponent < T > ( DependencyLifecycle dependencyLifecycle )
@@ -37,8 +38,9 @@ public void ConfigureComponent<T>(Func<T> componentFactory, DependencyLifecycle
37
38
return ;
38
39
}
39
40
40
- serviceCollection . Add ( new ServiceDescriptor ( componentType , p => componentFactory ( ) , Map ( dependencyLifecycle ) ) ) ;
41
- RegisterInterfaces ( componentType ) ;
41
+ var serviceLifetime = Map ( dependencyLifecycle ) ;
42
+ serviceCollection . Add ( new ServiceDescriptor ( componentType , p => componentFactory ( ) , serviceLifetime ) ) ;
43
+ RegisterInterfaces ( componentType , serviceLifetime ) ;
42
44
}
43
45
44
46
public void ConfigureComponent < T > ( Func < IBuilder , T > componentFactory , DependencyLifecycle dependencyLifecycle )
@@ -49,8 +51,9 @@ public void ConfigureComponent<T>(Func<IBuilder, T> componentFactory, Dependency
49
51
return ;
50
52
}
51
53
52
- serviceCollection . Add ( new ServiceDescriptor ( componentType , p => componentFactory ( new ServiceProviderAdapter ( p ) ) , Map ( dependencyLifecycle ) ) ) ;
53
- RegisterInterfaces ( componentType ) ;
54
+ var serviceLifetime = Map ( dependencyLifecycle ) ;
55
+ serviceCollection . Add ( new ServiceDescriptor ( componentType , p => componentFactory ( new ServiceProviderAdapter ( p ) ) , serviceLifetime ) ) ;
56
+ RegisterInterfaces ( componentType , serviceLifetime ) ;
54
57
}
55
58
56
59
public bool HasComponent < T > ( )
@@ -73,13 +76,13 @@ public void RegisterSingleton<T>(T instance)
73
76
RegisterSingleton ( typeof ( T ) , instance ) ;
74
77
}
75
78
76
- void RegisterInterfaces ( Type component )
79
+ void RegisterInterfaces ( Type component , ServiceLifetime serviceLifetime )
77
80
{
78
81
var interfaces = component . GetInterfaces ( ) ;
79
82
foreach ( var serviceType in interfaces )
80
83
{
81
84
// see https://andrewlock.net/how-to-register-a-service-with-multiple-interfaces-for-in-asp-net-core-di/
82
- serviceCollection . Add ( new ServiceDescriptor ( serviceType , sp => sp . GetService ( component ) , ServiceLifetime . Transient ) ) ;
85
+ serviceCollection . Add ( new ServiceDescriptor ( serviceType , sp => sp . GetService ( component ) , serviceLifetime ) ) ;
83
86
}
84
87
}
85
88
0 commit comments