public TransactionBehaviour( ITransactionalUnitOfWork transactionalUnitOfWork, ITransactionalOutboxService transactionalOutboxService, TransactionalOutboxConfiguration transactionalOutboxConfiguration, ILogger <TransactionBehaviour <TRequest, TResponse> > logger) { _transactionalUnitOfWork = transactionalUnitOfWork; _transactionalOutboxService = transactionalOutboxService; _transactionalOutboxConfiguration = transactionalOutboxConfiguration; _logger = logger; }
/// <summary> /// /// </summary> /// <param name="builder"></param> /// <param name="optionsBuilder">This should point to the same database as the one for UnitOfWork</param> /// <param name="configure"></param> /// <param name="enableAutoMigration"></param> /// <returns></returns> /// <exception cref="InvalidOperationException"></exception> public static WrapperizerContext AddOutboxServices( this WrapperizerContext builder, Action <DbContextOptionsBuilder> optionsBuilder, Action <TransactionalOutboxConfiguration> configure = null, bool enableAutoMigration = true) { if (_messageRelayServicesEnabled) { throw new InvalidOperationException(InvalidOperationExceptionMessage); } var configuration = new TransactionalOutboxConfiguration { AutoPublish = false }; configure?.Invoke(configuration); builder.Services.AddSingleton(configuration); builder.Services.AddDbContext <OutboxEventContext>(optionsBuilder); // ToDo: Change this to accept db from outside services not only the connection // and bear in mind that this one is a factory method builder.Services.AddTransient <Func <IOutboxEventService> >( services => () => { var outboxEventContext = services.GetRequiredService <OutboxEventContext>(); // new OutboxEventContext( // new DbContextOptionsBuilder<OutboxEventContext>() // .UseSqlServer(dbConnection) // .Options); return(new OutboxEventService(outboxEventContext)); }); builder.Services.AddTransient <ITransactionalOutboxService, TransactionalOutboxService>(); builder.Services.AddScoped <IOutboxMessageRelay, OutboxMessageRelay>(); if (enableAutoMigration) { builder.Services.AddHostedService <OutboxMigratorHostedService>(); } _outboxServicesEnabled = true; return(builder); //.Services; }
public static IServiceCollection AddOutboxServices( this IWrapperizerBuilder builder, Action <DbContextOptionsBuilder> optionsBuilder, Action <TransactionalOutboxConfiguration> configure = null, bool enableAutoMigration = true) { if (_messageRelayServicesEnabled) { throw new InvalidOperationException(InvalidOperationExceptionMessage); } var configuration = new TransactionalOutboxConfiguration { AutoPublish = false }; configure?.Invoke(configuration); builder.ServiceCollection.AddSingleton(configuration); builder.ServiceCollection.AddDbContext <OutboxEventContext>(optionsBuilder); builder.ServiceCollection.AddTransient <Func <DbConnection, IOutboxEventService> >( sp => dbConnection => // this dbConnection will be passed on // later on from implementations of integration service { var outboxEventContext = new OutboxEventContext( new DbContextOptionsBuilder <OutboxEventContext>() .UseSqlServer(dbConnection) .Options); return(new OutboxEventService(outboxEventContext)); }); builder.ServiceCollection.AddTransient <ITransactionalOutboxService, TransactionalOutboxService>(); builder.ServiceCollection.AddScoped <IOutboxMessageRelay, OutboxMessageRelay>(); if (enableAutoMigration) { builder.ServiceCollection.AddHostedService <OutboxMigratorHostedService>(); } return(builder.ServiceCollection); }