public OutboxEventService(OutboxEventContext context) { _outboxEventContext = context; var referencedAssemblies = Assembly.GetExecutingAssembly().WithEntryReferences(); _eventTypes = referencedAssemblies.SelectMany(assembly => assembly.GetTypes().Where(t => typeof(IntegrationEvent).IsAssignableFrom(t)) .ToList() ).ToList(); }
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); }