Skip to content

Commit

Permalink
Refactored OutboxExtensionAddOutbox (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
adimiko authored Jun 16, 2024
1 parent a059328 commit 2403a6c
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,7 @@ public static void AddOutbox(
assemblyConfiguraton(assemblyConfigurator);
}

var assemblies = assemblyConfigurator.Assemblies;

var allTypes = assemblyConfigurator.Assemblies.SelectMany(x => x.GetTypes());

var outboxMessageDefinitions = allTypes.Where(x => x.BaseType != null && x.BaseType.IsGenericType && x.BaseType.GetGenericTypeDefinition() == typeof(OutboxDefinition<>)).ToList();

foreach (var outboxMessageDefinition in outboxMessageDefinitions)
{
var messageType = outboxMessageDefinition.BaseType.GetGenericArguments()[0];

services.AddKeyedSingleton(typeof(IOutboxDefinition), messageType, outboxMessageDefinition);
}
services.RegisterOutboxMessageDefinitions(assemblyConfigurator);

services.AddSingleton<TransportEnvelopeFactory>();

Expand Down Expand Up @@ -112,5 +101,21 @@ public static void AddOutbox(

services.AddHostedService<OutboxStartup>();
}

private static void RegisterOutboxMessageDefinitions(this IServiceCollection services, AssemblyConfigurator assemblyConfigurator)
{
var assemblies = assemblyConfigurator.Assemblies;

var allTypes = assemblyConfigurator.Assemblies.SelectMany(x => x.GetTypes());

var outboxMessageDefinitions = allTypes.Where(x => x.BaseType != null && x.BaseType.IsGenericType && x.BaseType.GetGenericTypeDefinition() == typeof(OutboxDefinition<>)).ToList();

foreach (var outboxMessageDefinition in outboxMessageDefinitions)
{
var messageType = outboxMessageDefinition.BaseType.GetGenericArguments()[0];

Check warning on line 115 in source/TransactionalBox/Extensions/Outbox/OutboxExtensionAddOutbox.cs

View workflow job for this annotation

GitHub Actions / Build & Tests

Dereference of a possibly null reference.

services.AddKeyedSingleton(typeof(IOutboxDefinition), messageType, outboxMessageDefinition);
}
}
}
}

0 comments on commit 2403a6c

Please sign in to comment.