99namespace ModEndpoints . Core ;
1010public static class DependencyInjectionExtensions
1111{
12- public static IServiceCollection AddModEndpointsFromAssemblyCore (
12+ public static IServiceCollection AddModEndpointsCoreFromAssemblyContaining < T > (
1313 this IServiceCollection services ,
14- Assembly assembly )
14+ Assembly assembly ,
15+ ServiceLifetime lifetime = ServiceLifetime . Transient )
16+ {
17+ return services . AddModEndpointsCoreFromAssembly ( typeof ( T ) . Assembly , lifetime ) ;
18+ }
19+
20+ public static IServiceCollection AddModEndpointsCoreFromAssembly (
21+ this IServiceCollection services ,
22+ Assembly assembly ,
23+ ServiceLifetime lifetime = ServiceLifetime . Transient )
1524 {
1625 return services
17- . AddRouteGroupsFromAssemblyCore ( assembly )
18- . AddEndpointsFromAssemblyCore ( assembly ) ;
26+ . AddRouteGroupsCoreFromAssembly ( assembly , lifetime )
27+ . AddEndpointsCoreFromAssembly ( assembly , lifetime ) ;
1928 }
2029
21- private static IServiceCollection AddRouteGroupsFromAssemblyCore (
30+ private static IServiceCollection AddRouteGroupsCoreFromAssembly (
2231 this IServiceCollection services ,
23- Assembly assembly )
32+ Assembly assembly ,
33+ ServiceLifetime lifetime )
2434 {
2535 //Don't add RootRouteGroup, it's just a marker class to define root
2636 //Normally its assembly won't be loaded with this method anyway but just in case
@@ -29,17 +39,18 @@ private static IServiceCollection AddRouteGroupsFromAssemblyCore(
2939 . Where ( type => type is { IsAbstract : false , IsInterface : false } &&
3040 type . IsAssignableTo ( typeof ( IRouteGroupConfigurator ) ) &&
3141 type != typeof ( RootRouteGroup ) )
32- . Select ( type => ServiceDescriptor . KeyedTransient ( typeof ( IRouteGroupConfigurator ) , type , type ) )
42+ . Select ( type => ServiceDescriptor . DescribeKeyed ( typeof ( IRouteGroupConfigurator ) , type , type , lifetime ) )
3343 . ToArray ( ) ;
3444
3545 services . TryAddEnumerable ( serviceDescriptors ) ;
3646
3747 return services ;
3848 }
3949
40- public static IServiceCollection AddEndpointsFromAssemblyCore (
50+ public static IServiceCollection AddEndpointsCoreFromAssembly (
4151 this IServiceCollection services ,
42- Assembly assembly )
52+ Assembly assembly ,
53+ ServiceLifetime lifetime )
4354 {
4455 var endpointTypes = assembly
4556 . DefinedTypes
@@ -49,7 +60,7 @@ public static IServiceCollection AddEndpointsFromAssemblyCore(
4960 CheckServiceEndpointRegistrations ( endpointTypes ) ;
5061
5162 var serviceDescriptors = endpointTypes
52- . Select ( type => ServiceDescriptor . KeyedTransient ( typeof ( IEndpointConfigurator ) , type , type ) )
63+ . Select ( type => ServiceDescriptor . DescribeKeyed ( typeof ( IEndpointConfigurator ) , type , type , lifetime ) )
5364 . ToArray ( ) ;
5465
5566 services . TryAddEnumerable ( serviceDescriptors ) ;
0 commit comments