Переопределение ControllerFactory по умолчанию в пользовательском режиме, как сохранить его вызов в других случаях?C#

Место общения программистов C#
Anonymous
Переопределение ControllerFactory по умолчанию в пользовательском режиме, как сохранить его вызов в других случаях?

Сообщение Anonymous »

Как переопределить реализацию IControllerFactory по умолчанию с помощью пользовательской фабрики для пользовательских случаев и продолжать вызывать DefaultControllerFactory в обычных случаях, если DefaultControllerFactory стал внутренним классом в ASP.NET Core 3?
services.AddSingleton();

// this class for .NET core 2
public class MyCustomControllerFactory : DefaultControllerFactory
{
public override object CreateController(ControllerContext context)
{
//custom handling...

//base handling
return base.CreateController(context);
}

public override void ReleaseController(ControllerContext context, object controller)
{
base.ReleaseController(context, controller);
}
}

Класс DefaultControllerFactory в .NET 5 является внутренним, и я не могу вызвать его метод CreateController, чтобы попытаться зарегистрировать обычные контроллеры в среде ASP MVC Core 5.
//this class for .NET core 3 or .NET 5
public class MyCustomControllerFactory : IControllerFactory
{
public object CreateController(ControllerContext context)
{
if(/*is custom case*/)
{
/*custom actions*/
return /*custom IController*/
}
return /*in this place I want calling base.CreateController(context)*/;
}

public void ReleaseController(ControllerContext context, object controller)
{
var disposable = controller as IDisposable;
if (disposable != null) { disposable.Dispose(); }
}
}


Подробнее здесь: https://stackoverflow.com/questions/683 ... in-else-ca

Вернуться в «C#»