public static IServiceCollection AddDomainatorInfrastructure( this IServiceCollection services, Action <IDomainatorInfrastructureBuilder> configure) { Require.NotNull(services, nameof(services)); Require.NotNull(configure, nameof(configure)); var builder = new DomainatorInfrastructureBuilder(); configure(builder); services.AddSingleton(builder.StateStorageFactory); services.AddSingleton( provider => provider.GetRequiredService <StateStorageFactory>()(provider.GetService)); foreach (var repositoryType in builder.RegisteredRepositories) { services.Add(ServiceDescriptor.Scoped(repositoryType.InterfaceType, repositoryType.ImplementationType)); } services.AddSingleton <IAggregateStateSerializer, AggregateStateJsonSerializer>(provider => { var converters = new List <JsonConverter>(builder.CustomJsonConverters.Count); foreach (var converterType in builder.CustomJsonConverters) { converters.Add((JsonConverter)ActivatorUtilities.GetServiceOrCreateInstance(provider, converterType)); } return(new AggregateStateJsonSerializer(converters)); }); return(services); }
public void UseJsonConverter_AddsConverterTypeToCustomJsonConvertersCollection() { var builder = new DomainatorInfrastructureBuilder(); builder.Serialization.UseJsonConverter <UserIdJsonConverter>(); Assert.Contains(builder.CustomJsonConverters, type => type == typeof(UserIdJsonConverter)); }