public void ForEach_iterates_over_types() { var scanner = new AssemblyScanner(new[] { typeof(Model1Validator), typeof(Model2Validator) }); var results = new List <AssemblyScanner.AssemblyScanResult>(); scanner.ForEach(x => results.Add(x)); results.Count.ShouldEqual(2); }
public static IServiceCollection AddPipelines(this IServiceCollection services, Assembly[] assembliesForScan) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (assembliesForScan == null) { throw new ArgumentNullException(nameof(assembliesForScan)); } services.AddMediatR(assembliesForScan); services.TryAddEnumerable(ServiceDescriptor.Scoped(typeof(IPipelineBehavior <,>), typeof(ValidationPipelineBehavior <,>))); var assemblyScanner = new AssemblyScanner(assembliesForScan.SelectMany(a => a.GetTypes())); assemblyScanner.ForEach(t => { services.Add(ServiceDescriptor.Transient(t.InterfaceType, t.ValidatorType)); services.Add(ServiceDescriptor.Transient(t.ValidatorType, t.ValidatorType)); }); return(services); }