33// Code added/updated by Fedor Zhekov, GitHub: @ZFi88
44
55using System ;
6+ using System . Collections ;
7+ using System . Collections . Generic ;
68using System . Linq ;
79using System . Net . Http . Headers ;
810using System . Reflection ;
@@ -37,6 +39,7 @@ public static AutoRegisterData RegisterAssemblyPublicNonGenericClasses(this ISer
3739 /// <summary>
3840 /// This allows you to filter the classes in some way.
3941 /// For instance <code>Where(c =\> c.Name.EndsWith("Service")</code> would only register classes who's name ended in "Service"
42+ /// NOTE: You can have multiple calls to this method to apply a series off filters
4043 /// </summary>
4144 /// <param name="autoRegData"></param>
4245 /// <param name="predicate">A function that will take a type and return true if that type should be included</param>
@@ -69,10 +72,16 @@ public static AutoRegisterData IgnoreThisInterface<TInterface>(this AutoRegister
6972 /// <param name="autoRegData">AutoRegister data produced by <see cref="RegisterAssemblyPublicNonGenericClasses"/></param> method
7073 /// <param name="lifetime">Allows you to define the lifetime of the service - defaults to ServiceLifetime.Transient</param>
7174 /// <returns></returns>
72- public static IServiceCollection AsPublicImplementedInterfaces ( this AutoRegisterData autoRegData ,
75+ public static IList < AutoRegisteredResult > AsPublicImplementedInterfaces ( this AutoRegisterData autoRegData ,
7376 ServiceLifetime lifetime = ServiceLifetime . Transient )
7477 {
7578 if ( autoRegData == null ) throw new ArgumentNullException ( nameof ( autoRegData ) ) ;
79+
80+ //This lists all the ignored interfaces
81+ var result = autoRegData . InterfacesToIgnore . Select ( x =>
82+ new AutoRegisteredResult ( null , x , ServiceLifetime . Singleton ) )
83+ . ToList ( ) ;
84+
7685 foreach ( var classType in autoRegData . TypesToConsider )
7786 {
7887 if ( classType . IsMultipleLifetime ( ) )
@@ -83,11 +92,13 @@ public static IServiceCollection AsPublicImplementedInterfaces(this AutoRegister
8392 ! autoRegData . InterfacesToIgnore . Contains ( i ) //This will not register the class with this interface
8493 && i . IsPublic && ! i . IsNested ) )
8594 {
86- autoRegData . Services . Add ( new ServiceDescriptor ( infc , classType , classType . GetLifetimeForClass ( lifetime ) ) ) ;
95+ var lifetimeForClass = classType . GetLifetimeForClass ( lifetime ) ;
96+ autoRegData . Services . Add ( new ServiceDescriptor ( infc , classType , lifetimeForClass ) ) ;
97+ result . Add ( new AutoRegisteredResult ( classType , infc , lifetimeForClass ) ) ;
8798 }
8899 }
89100
90- return autoRegData . Services ;
101+ return result ;
91102 }
92103 }
93104}
0 commit comments