now supports interceptors for dynamic query.
This commit is contained in:
parent
0d3fbbcd01
commit
d01ac1601c
@ -1,5 +1,6 @@
|
|||||||
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
|
using PoweredSoft.CQRS.DynamicQuery.Abstractions;
|
||||||
using PoweredSoft.DynamicQuery.Core;
|
using PoweredSoft.DynamicQuery.Core;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -15,7 +16,7 @@ namespace PoweredSoft.CQRS.DynamicQuery
|
|||||||
{
|
{
|
||||||
public DynamicQueryHandler(IQueryHandlerAsync queryHandlerAsync,
|
public DynamicQueryHandler(IQueryHandlerAsync queryHandlerAsync,
|
||||||
IEnumerable<IQueryableProvider<TSource>> queryableProviders,
|
IEnumerable<IQueryableProvider<TSource>> queryableProviders,
|
||||||
IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices) : base(queryHandlerAsync, queryableProviders, alterQueryableServices)
|
IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices, IServiceProvider serviceProvider) : base(queryHandlerAsync, queryableProviders, alterQueryableServices, serviceProvider)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ namespace PoweredSoft.CQRS.DynamicQuery
|
|||||||
public DynamicQueryHandler(IQueryHandlerAsync queryHandlerAsync,
|
public DynamicQueryHandler(IQueryHandlerAsync queryHandlerAsync,
|
||||||
IEnumerable<IQueryableProvider<TSource>> queryableProviders,
|
IEnumerable<IQueryableProvider<TSource>> queryableProviders,
|
||||||
IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices,
|
IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices,
|
||||||
IEnumerable<IAlterQueryableService<TSource, TDestination, TParams>> alterQueryableServicesWithParams) : base(queryHandlerAsync, queryableProviders, alterQueryableServices)
|
IEnumerable<IAlterQueryableService<TSource, TDestination, TParams>> alterQueryableServicesWithParams, IServiceProvider serviceProvider) : base(queryHandlerAsync, queryableProviders, alterQueryableServices, serviceProvider)
|
||||||
{
|
{
|
||||||
this.alterQueryableServicesWithParams = alterQueryableServicesWithParams;
|
this.alterQueryableServicesWithParams = alterQueryableServicesWithParams;
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,17 @@ namespace PoweredSoft.CQRS.DynamicQuery
|
|||||||
private readonly IQueryHandlerAsync queryHandlerAsync;
|
private readonly IQueryHandlerAsync queryHandlerAsync;
|
||||||
private readonly IEnumerable<IQueryableProvider<TSource>> queryableProviders;
|
private readonly IEnumerable<IQueryableProvider<TSource>> queryableProviders;
|
||||||
private readonly IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices;
|
private readonly IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices;
|
||||||
|
private readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
public DynamicQueryHandlerBase(IQueryHandlerAsync queryHandlerAsync,
|
public DynamicQueryHandlerBase(IQueryHandlerAsync queryHandlerAsync,
|
||||||
IEnumerable<IQueryableProvider<TSource>> queryableProviders,
|
IEnumerable<IQueryableProvider<TSource>> queryableProviders,
|
||||||
IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices)
|
IEnumerable<IAlterQueryableService<TSource, TDestination>> alterQueryableServices,
|
||||||
|
IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
this.queryHandlerAsync = queryHandlerAsync;
|
this.queryHandlerAsync = queryHandlerAsync;
|
||||||
this.queryableProviders = queryableProviders;
|
this.queryableProviders = queryableProviders;
|
||||||
this.alterQueryableServices = alterQueryableServices;
|
this.alterQueryableServices = alterQueryableServices;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Task<IQueryable<TSource>> GetQueryableAsync(IDynamicQuery query, CancellationToken cancellationToken = default)
|
protected virtual Task<IQueryable<TSource>> GetQueryableAsync(IDynamicQuery query, CancellationToken cancellationToken = default)
|
||||||
@ -51,6 +54,23 @@ namespace PoweredSoft.CQRS.DynamicQuery
|
|||||||
var options = GetQueryExecutionOptions(source, query);
|
var options = GetQueryExecutionOptions(source, query);
|
||||||
var interceptors = this.GetInterceptors();
|
var interceptors = this.GetInterceptors();
|
||||||
|
|
||||||
|
// basic after read service.
|
||||||
|
var afterReadService1 = this.serviceProvider.GetService(typeof(IAfterReadInterceptorAsync<TSource>));
|
||||||
|
if (afterReadService1 is IQueryInterceptor ars1)
|
||||||
|
queryHandlerAsync.AddInterceptor(ars1);
|
||||||
|
|
||||||
|
// support of injecting a query convert interceptor.
|
||||||
|
if (typeof(TSource) != typeof(TDestination))
|
||||||
|
{
|
||||||
|
var convertService = this.serviceProvider.GetService(typeof(IQueryConvertInterceptor<TSource, TDestination>));
|
||||||
|
if (convertService is IQueryInterceptor cs)
|
||||||
|
queryHandlerAsync.AddInterceptor(cs);
|
||||||
|
|
||||||
|
var afterReadService2 = this.serviceProvider.GetService(typeof(IAfterReadInterceptorAsync<TSource, TDestination>));
|
||||||
|
if (afterReadService2 is IQueryInterceptor ars2)
|
||||||
|
queryHandlerAsync.AddInterceptor(ars2);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var interceptor in interceptors)
|
foreach (var interceptor in interceptors)
|
||||||
queryHandlerAsync.AddInterceptor(interceptor);
|
queryHandlerAsync.AddInterceptor(interceptor);
|
||||||
|
|
||||||
|
@ -94,5 +94,23 @@ namespace PoweredSoft.CQRS.DynamicQuery
|
|||||||
{
|
{
|
||||||
return services.AddTransient<IAlterQueryableService<TSource, TDestination, TParams>, TService>();
|
return services.AddTransient<IAlterQueryableService<TSource, TDestination, TParams>, TService>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddQueryConvertInterceptor<TSource, TDestination, TService>(this IServiceCollection services)
|
||||||
|
where TService : class, IQueryConvertInterceptor<TSource, TDestination>
|
||||||
|
{
|
||||||
|
return services.AddTransient<IQueryConvertInterceptor<TSource, TDestination>, TService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddAfterReadInterceptorAsync<TSource, TService>(this IServiceCollection services)
|
||||||
|
where TService : class, IAfterReadInterceptorAsync<TSource>
|
||||||
|
{
|
||||||
|
return services.AddTransient<IAfterReadInterceptorAsync<TSource>, TService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection AddAfterReadInterceptorAsync<TSource, TDestination, TService>(this IServiceCollection services)
|
||||||
|
where TService : class, IAfterReadInterceptorAsync<TSource, TDestination>
|
||||||
|
{
|
||||||
|
return services.AddTransient<IAfterReadInterceptorAsync<TSource, TDestination>, TService>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user