using Microsoft.Extensions.DependencyInjection; using PoweredSoft.CQRS.Abstractions.Discovery; using System; using System.Collections.Generic; using System.Text; namespace PoweredSoft.CQRS.Abstractions { public static class ServiceCollectionExtensions { public static IServiceCollection AddQuery(this IServiceCollection services) where TQuery : class where TQueryHandler : class, IQueryHandler { // add handler to DI. services.AddTransient, TQueryHandler>(); // add for discovery purposes. var queryMeta = new QueryMeta(typeof(TQuery), typeof(IQueryHandler), typeof(TQueryResult)); services.AddSingleton(queryMeta); return services; } public static IServiceCollection AddCommand(this IServiceCollection services) where TCommand : class where TCommandHandler : class, ICommandHandler { // add handler to DI. services.AddTransient, TCommandHandler>(); // add for discovery purposes. var commandMeta = new CommandMeta(typeof(TCommand), typeof(ICommandHandler), typeof(TCommandResult)); services.AddSingleton(commandMeta); return services; } public static IServiceCollection AddCommand(this IServiceCollection services) where TCommand : class where TCommandHandler : class, ICommandHandler { // add handler to DI. services.AddTransient, TCommandHandler>(); // add for discovery purposes. var commandMeta = new CommandMeta(typeof(TCommand), typeof(ICommandHandler)); services.AddSingleton(commandMeta); return services; } } }