public static IServiceCollection AddDataLoaderRegistry( this IServiceCollection services) { return(services .AddScoped <IDataLoaderRegistry, DataLoaderRegistry>() .AddScoped <IBatchOperation>(sp => { var batchOperation = new DataLoaderBatchOperation(); foreach (IDataLoaderRegistry registry in sp.GetServices <IDataLoaderRegistry>()) { registry.Subscribe(batchOperation); } return batchOperation; })); }
public static IServiceCollection AddDataLoaderRegistry( this IServiceCollection services) { if (services is null) { throw new ArgumentNullException(nameof(services)); } services.TryAddScoped <IDataLoaderRegistry, DataLoaderRegistry>(); services.TryAddScoped <IBatchOperation>(sp => { var batchOperation = new DataLoaderBatchOperation(); foreach (IDataLoaderRegistry registry in sp.GetServices <IDataLoaderRegistry>()) { registry.Subscribe(batchOperation); } return(batchOperation); }); return(services); }