public static IEventSourcingBuilder <IServiceCollection> Handle <TKey, TContent, TContext>( this IEventSourcingBuilder <IServiceCollection> builder, Func <TKey, TContent, TContext> transform, Action <IMiddlewareAppBuilder <TContext, IServiceCollection> > middlewareFactory) where TContext : IContext { builder.Configure( () => { var appBuilder = new MiddlewareAppBuilder <TContext, IServiceCollection> { Base = builder }; middlewareFactory(appBuilder); var middleware = appBuilder.Build(); builder.Base.AddScoped(sp => { MessageHandler <TKey, TContent> handler = async(key, content) => { var context = transform(key, content); context.Services = sp; await middleware(context); }; return(handler); }); } ); return(builder); }
public static IEventSourcingBuilder UseJsonEventSerializer( this IEventSourcingBuilder builder) { builder.Services .AddScoped <IObjectSerializer, JsonEventSerializer>() ; return(builder); }
public static IEventSourcingBuilder UseJsonEventSerializer( this IEventSourcingBuilder builder) { builder.Services .AddScoped(typeof(IObjectSerializer <>), typeof(JsonObjectSerializer <>)) .AddScoped(typeof(IJsonObjectSerializer <>), typeof(JsonObjectSerializer <>)) ; return(builder); }
public static IEventSourcingBuilder UseDbEventStore <TEventSourcingDbContext, TAggregate>( this IEventSourcingBuilder builder) where TEventSourcingDbContext : DbContext, IEventSourcingDbContext <TAggregate> where TAggregate : Aggregate { builder.Services .AddScoped <IEventStore <TAggregate>, DatabaseEventStore <TEventSourcingDbContext, TAggregate> >() ; return(builder); }
public static IEventSourcingBuilder UseCosmosDbEventStore <TEventSourcingDbContext, TAggregate, TAggregateKey>( this IEventSourcingBuilder builder) where TEventSourcingDbContext : DbContext, IEventSourcingDbContext <TAggregate, TAggregateKey> where TAggregate : IAggregate <TAggregateKey> { builder.Services .AddScoped <IEventStore <TAggregate, TAggregateKey>, DatabaseEventStore <TEventSourcingDbContext, TAggregate, TAggregateKey> >() .AddScoped <IEventStoreInitializer <TAggregate, TAggregateKey>, DefaultEventStoreInitializer <TAggregate, TAggregateKey> >() ; return(builder); }
public static IEventSourcingBuilder UseTextFileEventStore <TAggregate>( this IEventSourcingBuilder builder, Action <TextFileEventStoreOptions> setupAction) where TAggregate : Aggregate { builder.Services .AddScoped <IEventStore <TAggregate>, TextFileEventStore <TAggregate> >() .Configure(setupAction) ; return(builder); }
public static IEventSourcingBuilder UseS3SnapshotStore <TAggregate, TKey>( this IEventSourcingBuilder builder, Action <S3SnapshotStoreOptions> setupAction) where TAggregate : IAggregate <TKey> { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services .ConfigureAggregate <TAggregate, TKey, S3SnapshotStoreOptions>(setupAction) .AddScoped <ISnapshotStore <TAggregate, TKey>, S3SnapshotStore <TAggregate, TKey> >() ; return(builder); }
public static IEventSourcingBuilder Configure(this IEventSourcingBuilder eventSourcingBuilder, Action <EventSourcingOptions> configuration) { if (eventSourcingBuilder == null) { throw new ArgumentNullException(nameof(eventSourcingBuilder)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } eventSourcingBuilder.Services.Configure(configuration); return(eventSourcingBuilder); }
public static IEventSourcingBuilder UseEfCoreEventStore <TEventDbContext, TAggregate, TKey>( this IEventSourcingBuilder builder) where TEventDbContext : DbContext, IEventDbContext <TAggregate, TKey> where TAggregate : IAggregate <TKey> { if (builder is null) { throw new System.ArgumentNullException(nameof(builder)); } builder.Services .AddScoped <IEventStore <TAggregate, TKey>, EfCoreEventStore <TEventDbContext, TAggregate, TKey> >() .AddScoped <IEventStoreInitializer <TAggregate, TKey>, EfCoreEventStoreInitializer <TEventDbContext, TAggregate, TKey> >() ; return(builder.TryUseDefaultSnapshotStore <TAggregate, TKey>()); }
public static IEventSourcingBuilder UseCosmosDBEventStore <TAggregate, TKey>( this IEventSourcingBuilder builder, Action <CosmosDBEventStoreOptions> setupAction) where TAggregate : IAggregate <TKey> { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services .ConfigureAggregate <TAggregate, TKey, CosmosDBEventStoreOptions>(setupAction) .AddScoped <IEventStore <TAggregate, TKey>, CosmosDBEventStore <TAggregate, TKey> >() .AddScoped <IEventStoreInitializer <TAggregate, TKey>, CosmosDBEventStoreInitializer <TAggregate, TKey> >() ; return(builder.TryUseDefaultSnapshotStore <TAggregate, TKey>()); }
public static IEventSourcingBuilder <IServiceCollection> UseProjections( this IEventSourcingBuilder <IServiceCollection> builder) { builder.Handle <string, JObject, StringJObjectContext>( (k, v) => new StringJObjectContext { Content = v, Key = k }, (app) => { app .UseProjections(projApp => { projApp.FromServiceCollection(app.Base.Base); projApp.AttributeKeyResolution(); projApp.KeyFrom(x => x.Key); projApp.ContentFromJObject(); }); }); return(builder); }
public static IEventSourcingBuilder <IServiceCollection> FromKafka(this IEventSourcingBuilder <IServiceCollection> builder) { builder.Base.AddSingleton <IMessageHandler <string, byte[]>, EventMultiplexer>(); return(builder); }
public static IEventSourcingBuilder TryUseDefaultSnapshotStore <TAggregate, TKey>(this IEventSourcingBuilder builder) where TAggregate : IAggregate <TKey> { if (builder is null) { throw new System.ArgumentNullException(nameof(builder)); } builder.Services .TryAddScoped <ISnapshotStore <TAggregate, TKey>, DefaultSnapshotStore <TAggregate, TKey> >(); builder.Services .TryAddScoped <ISnapshotStoreInitializer <TAggregate, TKey>, DefaultSnapshotStoreInitializer <TAggregate, TKey> >(); return(builder); }
public static IEventSourcingBuilder <IServiceCollection> AddProjection <TProjection>(this IEventSourcingBuilder <IServiceCollection> builder) { var isProjection = typeof(TProjection) .GetInterfaces() .Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IProjection <>)); if (!isProjection) { throw new ArgumentException($"Type {typeof(TProjection).Name} cannot be registered because it does not implement IProjection<TEvent>"); } builder.Base.AddTransient(typeof(TProjection)); return(builder); }