using Microsoft.Extensions.DependencyInjection; using PoweredSoft.CQRS.Abstractions; using PoweredSoft.CQRS.Abstractions.Discovery; using PoweredSoft.CQRS.DynamicQuery.Abstractions; using PoweredSoft.CQRS.DynamicQuery.Discover; using PoweredSoft.DynamicQuery.Core; using System; using System.Collections.Generic; using System.Text; namespace PoweredSoft.CQRS.DynamicQuery { public static class ServiceCollectionExtensions { public static IServiceCollection AddDynamicQuery(this IServiceCollection services) where TSource : class where TDestination : class { // add query handler. services.AddTransient, IQueryExecutionResult>, DynamicQueryHandler>(); // add for discovery purposes. var queryType = typeof(IDynamicQuery); var resultType = typeof(IQueryExecutionResult); var serviceType = typeof(DynamicQueryHandler); var queryMeta = new DynamicQueryMeta(queryType, serviceType, resultType); services.AddSingleton(queryMeta); return services; } public static IServiceCollection AddDynamicQueryWithParams(this IServiceCollection services) where TSource : class where TDestination : class { // add query handler. services.AddTransient, IQueryExecutionResult>, DynamicQueryHandler>(); // add for discovery purposes. var queryType = typeof(IDynamicQuery); var resultType = typeof(IQueryExecutionResult); var serviceType = typeof(DynamicQueryHandler); var queryMeta = new DynamicQueryMeta(queryType, serviceType, resultType); // params type. queryMeta.ParamsType = typeof(TParams); services.AddSingleton(queryMeta); return services; } } }