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, string name = null) where TSourceAndDestination : class => AddDynamicQuery(services, name: name); public static IServiceCollection AddDynamicQuery(this IServiceCollection services, string name = null) 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) { OverridableName = name }; services.AddSingleton(queryMeta); return services; } public static IServiceCollection AddDynamicQueryWithParams(this IServiceCollection services, string name = null) where TSourceAndDestination : class where TParams : class => AddDynamicQueryWithParams(services, name: name); public static IServiceCollection AddDynamicQueryWithParams(this IServiceCollection services, string name = null) where TSource : class where TDestination : class where TParams : 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. ParamsType = typeof(TParams), OverridableName = name }; services.AddSingleton(queryMeta); return services; } public static IServiceCollection AddAlterQueryable(this IServiceCollection services) where TService : class, IAlterQueryableService { return services.AddTransient, TService>(); } public static IServiceCollection AddAlterQueryable(this IServiceCollection services) where TService : class, IAlterQueryableService { return services.AddTransient, TService>(); } public static IServiceCollection AddAlterQueryableWithParams (this IServiceCollection services) where TParams : class where TService : class, IAlterQueryableService { return services.AddTransient, TService>(); } public static IServiceCollection AddAlterQueryableWithParams (this IServiceCollection services) where TParams : class where TService : class, IAlterQueryableService { return services.AddTransient, TService>(); } public static IServiceCollection AddQueryConvertInterceptor(this IServiceCollection services) where TService : class, IQueryConvertInterceptor { return services.AddTransient, TService>(); } public static IServiceCollection AddAfterReadInterceptorAsync(this IServiceCollection services) where TService : class, IAfterReadInterceptorAsync { return services.AddTransient, TService>(); } public static IServiceCollection AddAfterReadInterceptorAsync(this IServiceCollection services) where TService : class, IAfterReadInterceptorAsync { return services.AddTransient, TService>(); } } }