From 972a4060ca6f3e27e471464303eefce9ef59da94 Mon Sep 17 00:00:00 2001 From: David Lebee Date: Tue, 2 Feb 2021 19:51:07 -0500 Subject: [PATCH] well advanced registration will use alter queryable service soon. --- Demo/Startup.cs | 4 +- .../IAlterQueryableService.cs | 18 +++++++++ .../ServiceCollectionExtensions.cs | 39 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 PoweredSoft.CQRS.DynamicQuery.Abstractions/IAlterQueryableService.cs diff --git a/Demo/Startup.cs b/Demo/Startup.cs index a5c290e..65304e3 100644 --- a/Demo/Startup.cs +++ b/Demo/Startup.cs @@ -62,8 +62,8 @@ namespace Demo private void AddDynamicQueries(IServiceCollection services) { services.AddTransient, ContactQueryableProvider>(); - services.AddDynamicQuery(); - services.AddDynamicQueryWithParams(name: "SearchContacts"); + services.AddDynamicQuery(); + services.AddDynamicQueryWithParams(name: "SearchContacts"); } private void AddCommands(IServiceCollection services) diff --git a/PoweredSoft.CQRS.DynamicQuery.Abstractions/IAlterQueryableService.cs b/PoweredSoft.CQRS.DynamicQuery.Abstractions/IAlterQueryableService.cs new file mode 100644 index 0000000..5e183d6 --- /dev/null +++ b/PoweredSoft.CQRS.DynamicQuery.Abstractions/IAlterQueryableService.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PoweredSoft.CQRS.DynamicQuery.Abstractions +{ + public interface IAlterQueryableService + { + Task> AlterQueryableAsync(IQueryable query, IDynamicQuery dynamicQuery); + } + public interface IAlterQueryableService + where TParams : class + { + Task> AlterQueryableAsync(IQueryable query, IDynamicQueryParams dynamicQuery); + } +} diff --git a/PoweredSoft.CQRS.DynamicQuery/ServiceCollectionExtensions.cs b/PoweredSoft.CQRS.DynamicQuery/ServiceCollectionExtensions.cs index 7554a4d..0b977a0 100644 --- a/PoweredSoft.CQRS.DynamicQuery/ServiceCollectionExtensions.cs +++ b/PoweredSoft.CQRS.DynamicQuery/ServiceCollectionExtensions.cs @@ -12,6 +12,10 @@ 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 @@ -33,7 +37,12 @@ namespace PoweredSoft.CQRS.DynamicQuery return services; } - public static IServiceCollection AddDynamicQueryWithParams(this IServiceCollection services, string name = null) + 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 @@ -57,5 +66,33 @@ namespace PoweredSoft.CQRS.DynamicQuery 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>(); + } } }