diff --git a/src/Merq.Core/MessageBus.cs b/src/Merq.Core/MessageBus.cs index e09d95e..123b673 100644 --- a/src/Merq.Core/MessageBus.cs +++ b/src/Merq.Core/MessageBus.cs @@ -394,7 +394,7 @@ static Type GetCommandType(IExecutable command) var generic = descriptor.ServiceType.GetGenericTypeDefinition(); // Consider both void and non-void handlers if (generic != typeof(IExecutableCommandHandler<>) && - generic != typeof(IExecutableCommandHandler<,>) && + generic != typeof(IExecutableCommandHandler<,>) && generic != typeof(ICommandHandler<>) && generic != typeof(ICommandHandler<,>) && generic != typeof(IAsyncCommandHandler<>) && diff --git a/src/Merq.Tests/ServiceCollectionExtensions.cs b/src/Merq.Tests/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..0b3020c --- /dev/null +++ b/src/Merq.Tests/ServiceCollectionExtensions.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.Extensions.DependencyInjection; + +namespace Merq; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddAll(this IServiceCollection services) + where TImplementation : class, new() + { + AddAll(services, _ => new TImplementation()); + return services; + } + + public static IServiceCollection AddAll( + this IServiceCollection services, + Func implementationFactory) + where TImplementation : class + { + // Simulates what the DependencyInjection.Attribute does, by registering + // the implementation with all the interfaces it implements. + + services.AddSingleton(implementationFactory); + + foreach (var interfaceType in typeof(TImplementation).GetInterfaces()) + services.AddSingleton(interfaceType, s => s.GetRequiredService(typeof(TImplementation))); + + return services; + } +}