public static IServiceCollection AddNotices(this IServiceCollection services, Action <NoticeServiceOptions> configureOptions, params Assembly[] assembliesToScan) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (assembliesToScan == null) { throw new ArgumentNullException(nameof(assembliesToScan)); } if (!assembliesToScan.Any()) { throw new ArgumentException("No assemblies found to scan. At least one assembly to scan for handlers is required"); } var options = new NoticeServiceOptions(); configureOptions?.Invoke(options); services.TryAdd(new ServiceDescriptor(typeof(INoticePublisher), options.PublisherType, options.Lifetime)); services .Scan(opt => opt.FromAssemblies(assembliesToScan) .AddClasses(classes => classes.AssignableTo(typeof(INoticeHandler <>))) .UsingRegistrationStrategy(RegistrationStrategy.Append) .AsImplementedInterfaces() //.As(c => c.GetInterfaces().Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(INoticeHandler<>))) .WithTransientLifetime()); return(services); }
public static IServiceCollection AddNotices(this IServiceCollection services, Action <NoticeServiceOptions> configureOptions, params Assembly[] assembliesToScan) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var options = new NoticeServiceOptions(); configureOptions?.Invoke(options); services.TryAdd(new ServiceDescriptor(typeof(INoticePublisher), options.PublisherType, options.PublisherServiceLifetime)); services.AddClasses(assembliesToScan); return(services); }