well advanced registration will use alter queryable service soon.

This commit is contained in:
David Lebee 2021-02-02 19:51:07 -05:00
parent 30e15e310c
commit 972a4060ca
3 changed files with 58 additions and 3 deletions

View File

@ -62,8 +62,8 @@ namespace Demo
private void AddDynamicQueries(IServiceCollection services) private void AddDynamicQueries(IServiceCollection services)
{ {
services.AddTransient<IQueryableProvider<Contact>, ContactQueryableProvider>(); services.AddTransient<IQueryableProvider<Contact>, ContactQueryableProvider>();
services.AddDynamicQuery<Contact, Contact>(); services.AddDynamicQuery<Contact>();
services.AddDynamicQueryWithParams<Contact, Contact, SearchContactParams>(name: "SearchContacts"); services.AddDynamicQueryWithParams<Contact, SearchContactParams>(name: "SearchContacts");
} }
private void AddCommands(IServiceCollection services) private void AddCommands(IServiceCollection services)

View File

@ -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<TSource, TDestination>
{
Task<IQueryable<TSource>> AlterQueryableAsync(IQueryable<TSource> query, IDynamicQuery dynamicQuery);
}
public interface IAlterQueryableService<TSource, TDestination, TParams>
where TParams : class
{
Task<IQueryable<TSource>> AlterQueryableAsync(IQueryable<TSource> query, IDynamicQueryParams<TParams> dynamicQuery);
}
}

View File

@ -12,6 +12,10 @@ namespace PoweredSoft.CQRS.DynamicQuery
{ {
public static class ServiceCollectionExtensions public static class ServiceCollectionExtensions
{ {
public static IServiceCollection AddDynamicQuery<TSourceAndDestination>(this IServiceCollection services, string name = null)
where TSourceAndDestination : class
=> AddDynamicQuery<TSourceAndDestination, TSourceAndDestination>(services, name: name);
public static IServiceCollection AddDynamicQuery<TSource, TDestination>(this IServiceCollection services, string name = null) public static IServiceCollection AddDynamicQuery<TSource, TDestination>(this IServiceCollection services, string name = null)
where TSource : class where TSource : class
where TDestination : class where TDestination : class
@ -33,7 +37,12 @@ namespace PoweredSoft.CQRS.DynamicQuery
return services; return services;
} }
public static IServiceCollection AddDynamicQueryWithParams<TSource, TDestination, TParams>(this IServiceCollection services, string name = null) public static IServiceCollection AddDynamicQueryWithParams<TSourceAndDestination, TParams>(this IServiceCollection services, string name = null)
where TSourceAndDestination : class
where TParams : class
=> AddDynamicQueryWithParams<TSourceAndDestination, TSourceAndDestination, TParams>(services, name: name);
public static IServiceCollection AddDynamicQueryWithParams<TSource, TDestination, TParams>(this IServiceCollection services, string name = null)
where TSource : class where TSource : class
where TDestination : class where TDestination : class
where TParams : class where TParams : class
@ -57,5 +66,33 @@ namespace PoweredSoft.CQRS.DynamicQuery
return services; return services;
} }
public static IServiceCollection AddAlterQueryable<TSourceAndDestination, TService>(this IServiceCollection services)
where TService : class, IAlterQueryableService<TSourceAndDestination, TSourceAndDestination>
{
return services.AddTransient<IAlterQueryableService<TSourceAndDestination, TSourceAndDestination>, TService>();
}
public static IServiceCollection AddAlterQueryable<TSource, TDestination, TService>(this IServiceCollection services)
where TService : class, IAlterQueryableService<TSource, TDestination>
{
return services.AddTransient<IAlterQueryableService<TSource, TDestination>, TService>();
}
public static IServiceCollection AddAlterQueryableWithParams<TSourceAndTDestination, TParams, TService>
(this IServiceCollection services)
where TParams : class
where TService : class, IAlterQueryableService<TSourceAndTDestination, TSourceAndTDestination, TParams>
{
return services.AddTransient<IAlterQueryableService< TSourceAndTDestination, TSourceAndTDestination, TParams>, TService>();
}
public static IServiceCollection AddAlterQueryableWithParams<TSource, TDestination, TParams, TService>
(this IServiceCollection services)
where TParams : class
where TService : class, IAlterQueryableService<TSource, TDestination, TParams>
{
return services.AddTransient<IAlterQueryableService<TSource, TDestination, TParams>, TService>();
}
} }
} }