-
Notifications
You must be signed in to change notification settings - Fork 280
Description
Is your feature request related to a problem? Please describe.
While migrating to V10 i stumbled opon this issue:
// Proper UseOutboxArchiver invocation looks like this:
brighterBuilder.UseOutboxArchiver<DbTransaction>(new NullOutboxArchiveProvider(), options => options.MinimumAge = TimeSpan.FromDays(4));
// But that would require knowing the transaction type at compile time. And we don't, since there will be different transaction types for mongo and relational dbs.Since we support using Postgres or MongoDB as a outbox provider - we cannot set the DbTransaction generic type during setting up the outbox archiver. I've found this workaround to work:
typeof(HostedServiceCollectionExtensions)
.GetMethod(nameof(HostedServiceCollectionExtensions.UseOutboxArchiver))!
.MakeGenericMethod(transactionType)
.Invoke(null, [
brighterBuilder,
new NullOutboxArchiveProvider(),
new Action<TimedOutboxArchiverOptions>(opt => opt.MinimumAge = TimeSpan.FromDays(4))
]);The transactionType is passed down from microservice configuration and can be either mongo or postgres implementation. I think you are using similar logic when registering the outbox in AddProducers:
Brighter/src/Paramore.Brighter.Extensions.DependencyInjection/ServiceCollectionExtensions.cs
Lines 166 to 178 in fc3933f
| //default to using System Transactions if nothing provided, so we always technically can share the outbox transaction | |
| Type transactionProvider = busConfiguration.TransactionProvider ?? typeof(InMemoryTransactionProvider); | |
| //Find the transaction type from the provider | |
| Type transactionProviderInterface = typeof(IAmABoxTransactionProvider<>); | |
| Type? transactionType = null; | |
| foreach (Type i in transactionProvider.GetInterfaces()) | |
| { | |
| if (i.IsGenericType && i.GetGenericTypeDefinition() == transactionProviderInterface) | |
| { | |
| transactionType = i.GetGenericArguments()[0]; | |
| } | |
| } |
I think the same (or similar) logic can be performed in the UseOutboxArchiver helper (although i didn't analyze this to know for sure).
Describe the solution you'd like
Ideally, UseOutboxArchiver should infer the transactionType automatically (i think it was the case in v9)