public static IFuxionBuilder EntityFrameworkSqlServer <TContext>(this IFuxionBuilder me, out Func <IServiceProvider, TContext> builder, string dataSource, string initialCatalog, string userID = null, string password = null) where TContext : DbContext { me.Services.AddDbContext <TContext>(options => { var connectionBuilder = new SqlConnectionStringBuilder { DataSource = dataSource, InitialCatalog = initialCatalog }; if (string.IsNullOrWhiteSpace(userID) || string.IsNullOrWhiteSpace(password)) { connectionBuilder.IntegratedSecurity = true; } else { connectionBuilder.UserID = userID; connectionBuilder.Password = password; } options.UseSqlServer( connectionBuilder.ConnectionString, sqlServerOptionsAction: sqlOptions => { sqlOptions.MigrationsAssembly(typeof(TContext).GetTypeInfo().Assembly.GetName().Name); //Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency sqlOptions.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); }); }); builder = new Func <IServiceProvider, TContext>(sp => sp.GetRequiredService <TContext>()); return(me); }
public static IFuxionBuilder RabbitMQ(this IFuxionBuilder me, out Func <IServiceProvider, RabbitMQEventBus> builder, string exchangeName, string queueName, string connectionHost = "localhost", int connectionRetryCount = 5, int queueRetryCount = 5) { me.Services.AddSingleton <IRabbitMQPersistentConnection>(new DefaultRabbitMQPersistentConnection(new ConnectionFactory() { HostName = connectionHost }, connectionRetryCount)); builder = new Func <IServiceProvider, RabbitMQEventBus>(sp => { var bus = new RabbitMQEventBus( sp, sp.GetRequiredService <IRabbitMQPersistentConnection>(), sp.GetRequiredService <TypeKeyDirectory>(), exchangeName, queueName, queueRetryCount); // Esto se ejecutará al activar la instancia de RabbitMQEventBus // Suscribo los eventos externos. Se manejarán mediante EventHandlers igual que los eventos del propio bounded context foreach (var sub in sp.GetServices <EventSubscription>()) { bus.Subscribe(sub.EventType); } return(bus); }); me.Services.AddSingleton(builder); me.AddToAutoActivateList <RabbitMQEventBus>(); return(me); }
public static IFuxionBuilder EntityFrameworkInMemory <TContext>(this IFuxionBuilder me, out Func <IServiceProvider, TContext> builder, string databaseName) where TContext : DbContext { me.Services.AddDbContext <TContext>(options => { options.UseInMemoryDatabase(databaseName); }); builder = new Func <IServiceProvider, TContext>(sp => sp.GetRequiredService <TContext>()); return(me); }
public static IFuxionBuilder Aggregate <TAggregate, TAggregateFactory, TAggregateRepository>( this IFuxionBuilder me, Func <IServiceProvider, IEventPublisher> eventPublisher = null) where TAggregate : Aggregate, new() where TAggregateFactory : Factory <TAggregate> where TAggregateRepository : class, IRepository <TAggregate> { Aggregate <TAggregate, TAggregateFactory>(me, eventPublisher); me.Services.AddScoped <TAggregateRepository>(); me.Services.AddScoped <IRepository <TAggregate> >(sp => sp.GetRequiredService <TAggregateRepository>()); return(me); }
public static IFuxionBuilder Aggregate <TAggregate, TAggregateFactory>( this IFuxionBuilder me, Func <IServiceProvider, IEventStorage> eventStorage, Func <IServiceProvider, IEventPublisher> eventPublisher = null) where TAggregate : Aggregate, new() where TAggregateFactory : Factory <TAggregate> { Aggregate <TAggregate, TAggregateFactory>(me, eventPublisher); me.Services.AddScoped <IRepository <TAggregate>, EventSourcingRepository <TAggregate> >(); me.Services.AddTransient <IFactoryFeature <TAggregate>, EventSourcingFactoryFeature <TAggregate> >(); // I don't have to register IEventStorage, i must register IEventStorage<TAggregate>. Because of this, i use the decorator. me.Services.AddSingleton <IEventStorage <TAggregate> >(sp => new EventStorageDecorator <TAggregate>(eventStorage(sp))); return(me); }
public static IFuxionBuilder Aggregate <TAggregate, TAggregateFactory, TSnapshot>( this IFuxionBuilder me, Func <IServiceProvider, IEventStorage> eventStorage, Func <IServiceProvider, ISnapshotStorage> snapshotStorage, int snapshotFrecuency = 3, Func <IServiceProvider, IEventPublisher> eventPublisher = null) where TAggregate : Aggregate, new() where TAggregateFactory : Factory <TAggregate> where TSnapshot : Snapshot <TAggregate> { Aggregate <TAggregate, TAggregateFactory>(me, eventStorage, eventPublisher); me.TypeKeyDirectory.Register <TSnapshot>(); me.Services.AddSingleton <IFactoryFeature <TAggregate> >(sp => new SnapshotFactoryFeature <TAggregate>(typeof(TSnapshot), snapshotFrecuency)); // I don't have to register ISnapshotStorage, i must register ISnapshotStorage<TAggregate>. Because of this, i use the decorator. me.Services.AddSingleton <ISnapshotStorage <TAggregate> >(sp => new SnapshotStorageDecorator <TAggregate>(snapshotStorage(sp))); return(me); }
public static IFuxionBuilder Aggregate <TAggregate, TAggregateFactory>( this IFuxionBuilder me, Func <IServiceProvider, IEventPublisher> eventPublisher = null) where TAggregate : Aggregate, new() where TAggregateFactory : Factory <TAggregate> { me.Services.AddScoped <TAggregateFactory>(); me.Services.AddScoped <Factory <TAggregate> >(sp => sp.GetRequiredService <TAggregateFactory>()); if (eventPublisher != null) { me.Services.AddTransient <IFactoryFeature <TAggregate>, EventsFactoryFeature <TAggregate> >(); //AggregateFactory<TAggregate>.Initializer.OnInitialize(a => a.AttachEvents()); // I don't have to register IEventPublisher, i must register IEventPublisher<TAggregate>. Because of this, i use the decorator. me.Services.AddSingleton <IEventPublisher <TAggregate> >(sp => new EventPublisherDecorator <TAggregate>(eventPublisher(sp))); } return(me); }
public static IFuxionBuilder Shell(this IFuxionBuilder me, Action <IShellBuilder> builder) { me.Services.AddSingleton <Cache>(); me.Services.AddSingleton <MenuManager>(); me.Services.AddSingleton <DockingManager>(); me.Services.AddSingleton <ShellViewModel>(); me.Services.AddSingleton <ShellWindow>(); me.AddToPostRegistrationList(serviceProvider => { foreach (var module in serviceProvider.GetServices <IModule>()) { module.Register(me.Services); } }); var shellBuilder = new ShellBuilder(me); me.AddToAutoActivateList <ShellWindow>(preAction: serviceProvider => { foreach (var module in serviceProvider.GetServices <IModule>()) { module.Initialize(serviceProvider); } }, postAction: (_, win) => { shellBuilder.ShellWindow = win; if (shellBuilder.ShowWindow) { win.Show(); } }); builder(shellBuilder); return(me); }
public ShellBuilder(IFuxionBuilder fuxionBuilder) => FuxionBuilder = fuxionBuilder;
public static IFuxionBuilder InMemorySnapshotStorage(this IFuxionBuilder me, out Func <IServiceProvider, InMemorySnapshotStorage> builder, string dumpFilePath = null) { builder = new Func <IServiceProvider, InMemorySnapshotStorage>(sp => new InMemorySnapshotStorage(sp.GetRequiredService <TypeKeyDirectory>(), dumpFilePath)); me.Services.AddSingleton(builder); return(me); }
public CommandsBuilder(IFuxionBuilder fuxionBuilder) => FuxionBuilder = fuxionBuilder;
public EventsBuilder(IFuxionBuilder fuxionBuilder) => FuxionBuilder = fuxionBuilder;
public static IFuxionBuilder Commands(this IFuxionBuilder me, Action <ICommandsBuilder> builderAction) { me.Services.AddScoped <ICommandDispatcher, CommandDispatcher>(); builderAction(new CommandsBuilder(me)); return(me); }
public static IFuxionBuilder Events(this IFuxionBuilder me, Action <IEventsBuilder> builderAction) { me.Services.AddScoped <IEventDispatcher, EventDispatcher>(); builderAction(new EventsBuilder(me)); return(me); }