【问题标题】:Can't Instantiate Windsor Custom Component Activator无法实例化 Windsor 自定义组件激活器
【发布时间】:2010-06-11 23:09:32
【问题描述】:

我在调用 Resolve 时遇到异常:

KernelException: Could not instantiate custom activator
Inner Exception:
{"Constructor on type 'MyProj.MyAdapter`1[[MyProj.MyBusinessObject, MyAsm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' not found."}

那里肯定有一个公共的无参数构造函数(我已经在运行时使用反射验证了这一点)......所以我认为问题可能与它是通用的事实有关?我已经尝试获取组件模型对象并将 RequiresGenericArguments 设置为 true,但这并没有让我得到任何结果。

任何帮助将不胜感激!谢谢。

【问题讨论】:

    标签: castle-windsor ioc-container activator microkernel


    【解决方案1】:

    Windsor 没有使用默认构造函数来实例化激活器。

    新版本抛出更有用的异常信息:

    Castle.MicroKernel.KernelException : Could not instantiate custom activator
      ----> System.ArgumentException : Type Castle.Windsor.Tests.ActivatorWithoutCorrectConstructor does not have a public constructor matching arguments of the following types:
    Castle.Core.ComponentModel
    Castle.MicroKernel.DefaultKernel
    Castle.MicroKernel.ComponentInstanceDelegate
    Castle.MicroKernel.ComponentInstanceDelegate
    

    所以你需要这样的构造函数

    public YourActivator(ComponentModel model, IKernel kernel,
                                        ComponentInstanceDelegate onCreation,
                                        ComponentInstanceDelegate onDestruction)
    

    【讨论】:

      猜你喜欢
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2017-03-18
      • 1970-01-01
      • 2016-09-25
      • 2013-11-22
      相关资源
      最近更新 更多