2021-02-02 19:01:29 -05:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-02-02 19:51:07 -05:00
|
|
|
|
public static IServiceCollection AddDynamicQuery<TSourceAndDestination>(this IServiceCollection services, string name = null)
|
|
|
|
|
where TSourceAndDestination : class
|
|
|
|
|
=> AddDynamicQuery<TSourceAndDestination, TSourceAndDestination>(services, name: name);
|
|
|
|
|
|
2021-02-02 19:32:39 -05:00
|
|
|
|
public static IServiceCollection AddDynamicQuery<TSource, TDestination>(this IServiceCollection services, string name = null)
|
2021-02-02 19:01:29 -05:00
|
|
|
|
where TSource : class
|
|
|
|
|
where TDestination : class
|
|
|
|
|
{
|
|
|
|
|
// add query handler.
|
|
|
|
|
services.AddTransient<PoweredSoft.CQRS.Abstractions.IQueryHandler<IDynamicQuery<TSource, TDestination>, IQueryExecutionResult<TDestination>>, DynamicQueryHandler<TSource, TDestination>>();
|
|
|
|
|
|
|
|
|
|
// add for discovery purposes.
|
|
|
|
|
var queryType = typeof(IDynamicQuery<TSource, TDestination>);
|
|
|
|
|
var resultType = typeof(IQueryExecutionResult<TDestination>);
|
|
|
|
|
var serviceType = typeof(DynamicQueryHandler<TSource, TDestination>);
|
2021-02-02 19:32:39 -05:00
|
|
|
|
var queryMeta = new DynamicQueryMeta(queryType, serviceType, resultType)
|
|
|
|
|
{
|
|
|
|
|
OverridableName = name
|
|
|
|
|
};
|
2021-02-02 19:01:29 -05:00
|
|
|
|
|
|
|
|
|
services.AddSingleton<IQueryMeta>(queryMeta);
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 19:51:07 -05:00
|
|
|
|
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)
|
2021-02-02 19:01:29 -05:00
|
|
|
|
where TSource : class
|
|
|
|
|
where TDestination : class
|
2021-02-02 19:32:39 -05:00
|
|
|
|
where TParams : class
|
2021-02-02 19:01:29 -05:00
|
|
|
|
{
|
|
|
|
|
// add query handler.
|
2021-02-02 19:32:39 -05:00
|
|
|
|
services.AddTransient<PoweredSoft.CQRS.Abstractions.IQueryHandler<IDynamicQuery<TSource, TDestination, TParams>, IQueryExecutionResult<TDestination>>, DynamicQueryHandler<TSource, TDestination, TParams>>();
|
2021-02-02 19:01:29 -05:00
|
|
|
|
|
|
|
|
|
// add for discovery purposes.
|
2021-02-02 19:32:39 -05:00
|
|
|
|
var queryType = typeof(IDynamicQuery<TSource, TDestination, TParams>);
|
2021-02-02 19:01:29 -05:00
|
|
|
|
var resultType = typeof(IQueryExecutionResult<TDestination>);
|
|
|
|
|
var serviceType = typeof(DynamicQueryHandler<TSource, TDestination>);
|
2021-02-02 19:32:39 -05:00
|
|
|
|
var queryMeta = new DynamicQueryMeta(queryType, serviceType, resultType)
|
|
|
|
|
{
|
2021-02-02 19:01:29 -05:00
|
|
|
|
|
2021-02-02 19:32:39 -05:00
|
|
|
|
// params type.
|
|
|
|
|
ParamsType = typeof(TParams),
|
|
|
|
|
OverridableName = name
|
|
|
|
|
};
|
2021-02-02 19:01:29 -05:00
|
|
|
|
|
|
|
|
|
services.AddSingleton<IQueryMeta>(queryMeta);
|
|
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
2021-02-02 19:51:07 -05:00
|
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
}
|
2021-02-02 20:39:59 -05:00
|
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
}
|
2021-02-02 19:01:29 -05:00
|
|
|
|
}
|
|
|
|
|
}
|