@@ -20,13 +20,14 @@ public static class AutoRegisterHelpers
2020 /// <param name="services">the NET Core dependency injection service</param>
2121 /// <param name="assemblies">Each assembly you want scanned. If null then scans the the assembly that called the method</param>
2222 /// <returns></returns>
23- public static AutoRegisterData RegisterAssemblyPublicNonGenericClasses ( this IServiceCollection services , params Assembly [ ] assemblies )
23+ public static AutoRegisterData RegisterAssemblyPublicNonGenericClasses ( this IServiceCollection services ,
24+ params Assembly [ ] assemblies )
2425 {
2526 if ( assemblies . Length == 0 )
2627 assemblies = new [ ] { Assembly . GetCallingAssembly ( ) } ;
2728
2829 var allPublicTypes = assemblies . SelectMany ( x => x . GetExportedTypes ( )
29- . Where ( y => y . IsClass && ! y . IsAbstract && ! y . IsGenericType && ! y . IsNested ) ) ;
30+ . Where ( y => y . IsClass && ! y . IsAbstract && ! y . IsGenericType && ! y . IsNested && ! y . IsIgnoredType ( ) ) ) ;
3031 return new AutoRegisterData ( services , allPublicTypes ) ;
3132 }
3233
@@ -48,17 +49,19 @@ public static AutoRegisterData Where(this AutoRegisterData autoRegData, Func<Typ
4849 /// This registers the classes against any public interfaces (other than IDisposable) implemented by the class
4950 /// </summary>
5051 /// <param name="autoRegData">AutoRegister data produced by <see cref="RegisterAssemblyPublicNonGenericClasses"/></param> method
51- /// <param name="lifetime">Allows you to define the lifetime of the service - defaults to ServiceLifetime.Transient</param>
5252 /// <returns></returns>
53- public static IServiceCollection AsPublicImplementedInterfaces ( this AutoRegisterData autoRegData ,
54- ServiceLifetime lifetime = ServiceLifetime . Transient )
53+ public static IServiceCollection AsPublicImplementedInterfaces ( this AutoRegisterData autoRegData )
5554 {
5655 if ( autoRegData == null ) throw new ArgumentNullException ( nameof ( autoRegData ) ) ;
57- foreach ( var classType in ( autoRegData . TypeFilter == null
58- ? autoRegData . TypesToConsider
56+ foreach ( var classType in ( autoRegData . TypeFilter == null
57+ ? autoRegData . TypesToConsider
5958 : autoRegData . TypesToConsider . Where ( autoRegData . TypeFilter ) ) )
6059 {
60+ if ( classType . IsMultipleLifetime ( ) )
61+ throw new ArgumentException ( $ "Class { classType . FullName } has multiple life time attributes") ;
62+
6163 var interfaces = classType . GetTypeInfo ( ) . ImplementedInterfaces ;
64+ var lifetime = classType . GetTypeLiteTime ( ) ;
6265 foreach ( var infc in interfaces . Where ( i => i != typeof ( IDisposable ) && i . IsPublic && ! i . IsNested ) )
6366 {
6467 autoRegData . Services . Add ( new ServiceDescriptor ( infc , classType , lifetime ) ) ;
@@ -68,4 +71,4 @@ public static IServiceCollection AsPublicImplementedInterfaces(this AutoRegister
6871 return autoRegData . Services ;
6972 }
7073 }
71- }
74+ }
0 commit comments