1c81288895
refactor the name of the organisation
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using Microsoft.AspNetCore.Mvc.ApplicationParts;
|
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using OpenHarbor.CQRS.Abstractions.Discovery;
|
|
using OpenHarbor.CQRS.AspNetCore.Abstractions.Attributes;
|
|
|
|
namespace OpenHarbor.CQRS.AspNetCore.Mvc;
|
|
|
|
public class QueryControllerFeatureProvider : IApplicationFeatureProvider<ControllerFeature>
|
|
{
|
|
private readonly ServiceProvider _serviceProvider;
|
|
|
|
public QueryControllerFeatureProvider(ServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public void PopulateFeature(IEnumerable<ApplicationPart> parts, ControllerFeature feature)
|
|
{
|
|
var queryDiscovery = this._serviceProvider.GetRequiredService<IQueryDiscovery>();
|
|
foreach (var f in queryDiscovery.GetQueries())
|
|
{
|
|
var ignoreAttribute = f.QueryType.GetCustomAttribute<QueryControllerIgnoreAttribute>();
|
|
if (ignoreAttribute != null)
|
|
continue;
|
|
|
|
if (f.Category != "BasicQuery")
|
|
continue;
|
|
|
|
var controllerType = typeof(QueryController<,>).MakeGenericType(f.QueryType, f.QueryResultType);
|
|
var controllerTypeInfo = controllerType.GetTypeInfo();
|
|
feature.Controllers.Add(controllerTypeInfo);
|
|
}
|
|
}
|
|
} |