public static IServiceCollection ScanValidations(this IServiceCollection services, params string[] assemblies) { GenerateValidations(CoreUtils .GetListOfTypes(assemblies, (type) => !(type.GetCustomAttribute(typeof(DomainValidationNameAttribute)) is null))); return(services); }
/// <summary> /// Extension from Microsoft.Extensions.DependencyInjection. /// This method auto scan all classes with the attribute,<remarks>InjectableAttribute</remarks> and put automatically in the container services. /// </summary> /// <example> /// <code> /// public interface ITest1 {} /// /// [InjectableAttribute(typeof(ITest1))] /// public class Class1 : ITest1{ } /// /// [InjectableAttribute(typeof(ITest1), DependencyInjectionTypes.Scoped)] /// public class Class1 : ITest1{ } /// /// [InjectableAttribute(typeof(ITest1), DependencyInjectionTypes.Scoped, "myClass1")] /// public class Class1 : ITest1{ } /// </code> /// </example> /// <param name="services"></param> /// <param name="assemblies">Assemblies list by comma, or GetEntryAssembly by default</param> /// <returns>ISericeCollection to continue the configuration.</returns> public static IServiceCollection ScanInjections(this IServiceCollection services, params string[] assemblies) { if (services == null) { throw new ArgumentNullException(nameof(services)); } InjectionFactory.Clear(); foreach (Type zclass in CoreUtils.GetListOfTypes(assemblies)) { foreach (var injectable in zclass.GetTypeInfo().GetCustomAttributes <InjectableAttribute>()) { foreach (var zinterface in zclass.GetTypeInfo().ImplementedInterfaces) { AddInjection(services, injectable.DependencyType, zinterface, zclass); AddInternalInjection(injectable.Name, zclass); } } } return(services); }