1c81288895
refactor the name of the organisation
27 lines
1.1 KiB
C#
27 lines
1.1 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using OpenHarbor.CQRS.Abstractions.Discovery;
|
|
|
|
namespace OpenHarbor.CQRS.DynamicQuery.AspNetCore.Mvc;
|
|
|
|
public class DynamicQueryControllerConvention : IControllerModelConvention
|
|
{
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public DynamicQueryControllerConvention(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
}
|
|
|
|
public void Apply(ControllerModel controller)
|
|
{
|
|
if (controller.ControllerType.IsGenericType && controller.ControllerType.Name.Contains("DynamicQueryController") && controller.ControllerType.Assembly == typeof(DynamicQueryControllerConvention).Assembly)
|
|
{
|
|
var genericType = controller.ControllerType.GenericTypeArguments[0];
|
|
var queryDiscovery = _serviceProvider.GetRequiredService<IQueryDiscovery>();
|
|
var query = queryDiscovery.FindQuery(genericType);
|
|
controller.ControllerName = query.LowerCamelCaseName;
|
|
}
|
|
}
|
|
} |