public static IServiceCollection ConfigureRepositories(this IServiceCollection services, bool excludeTests = true) { var assemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(x => !x.IsDynamic).ToArray(); if (excludeTests) { assemblies = assemblies .Where(x => !x.FullName.Contains("Test", StringComparison.InvariantCultureIgnoreCase)) .ToArray(); } var aggregates = AssemblyScanner.FindAggregates(assemblies); var implementedEventStore = typeof(MongoEventStore <,>); foreach (var kv in aggregates) { var eventStoreInterface = typeof(IEventStore <,>).MakeGenericType(kv.Key, kv.Value); var repositoryInterface = typeof(IAggregateRepository <,>).MakeGenericType(kv.Key, kv.Value); var concreteRepository = typeof(AggregateRepository <,>).MakeGenericType(kv.Key, kv.Value); var concreteEventStore = typeof(MongoEventStore <,>).MakeGenericType(kv.Key, kv.Value); services.AddSingleton(eventStoreInterface, concreteEventStore); services.AddSingleton(repositoryInterface, concreteRepository); } return(services); }
public static IServiceCollection RegisterStores(this IServiceCollection services, bool excludeTests = true) { var assemblies = AppDomain.CurrentDomain.GetAssemblies() .Where(x => !x.IsDynamic).ToArray(); if (excludeTests) { assemblies = assemblies .Where(x => // ReSharper disable once PossibleNullReferenceException !x.FullName.Contains("Test", StringComparison.InvariantCultureIgnoreCase)) .ToArray(); } var aggregates = AssemblyScanner.FindAggregates(assemblies); foreach (var kv in aggregates) { var eventStoreInterface = typeof(IEventStore <,>).MakeGenericType(kv.Key, kv.Value); var concreteEventStore = typeof(MongoEventStore <,>).MakeGenericType(kv.Key, kv.Value); services.AddTransient(eventStoreInterface, concreteEventStore); } return(services); }