C# Unity mvc控制器的单个实例'';无法用于处理多个请求

C# Unity mvc控制器的单个实例'';无法用于处理多个请求,c#,dependency-injection,unity-container,C#,Dependency Injection,Unity Container,我有一个MVC5应用程序。我使用Unity作为我的DI。 在我的应用程序中,我的控制器有两个动作: 主要作用 儿童行动 我的主操作视图调用Html.RenderAction(“ChildAction”) 我得到下一个错误: A single instance of controller '' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that

我有一个MVC5应用程序。我使用Unity作为我的DI。 在我的应用程序中,我的控制器有两个动作:

  • 主要作用
  • 儿童行动
我的主操作视图调用Html.RenderAction(“ChildAction”)

我得到下一个错误:

A single instance of controller '' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.
我尝试了许多解决方案,例如创建自定义的“UnityController工厂”:

向“TransientLifetimeManager”注册控制器:

container.RegisterType(新的TransientLifetimeManager());
什么都没用


非常感谢您的帮助。

在调用
容器后,您为什么要调用
base.GetControllerInstance
。请解决
?抱歉,代码复制错误,这是以前测试的遗留问题。我删除了这条线
  public class UnityControllerFactory : DefaultControllerFactory
{
    IUnityContainer container;

    public UnityControllerFactory(IUnityContainer container)
    {
        this.container = container;
    }

    public override IController CreateController(RequestContext context, string controllerName)
    {
        Type type = GetControllerType(context, controllerName);

        if (type == null)
        {
            throw new InvalidOperationException(string.Format("Could not find a controller with the name {0}", controllerName));
        }



        return (IController)container.Resolve(type);
    }

    protected override IController GetControllerInstance(RequestContext reqContext, Type controllerType)
    {
        IController controller;
        if (controllerType == null)
            throw new HttpException(
                    404, String.Format(
                        "The controller for path '{0}' could not be found" +
        "or it does not implement IController.",
                    reqContext.HttpContext.Request.Path));

        if (!typeof(IController).IsAssignableFrom(controllerType))
            throw new ArgumentException(
                    string.Format(
                        "Type requested is not a controller: {0}",
                        controllerType.Name),
                        "controllerType");
        try
        {
            controller = container.Resolve(controllerType)
                            as IController;


        }
        catch (Exception ex)
        {
            throw new InvalidOperationException(String.Format(
                                    "Error resolving controller {0}",
                                    controllerType.Name), ex);
        }
        return controller;
    }
    public override void ReleaseController(IController controller)
    {
        container.Teardown(controller);
    }
container.RegisterType<TestController>(new TransientLifetimeManager());