温莎城堡罐头';在程序集中找不到安装程序

本文关键字:程序 程序集 集中 找不到 安装 城堡 罐头 | 更新日期: 2023-09-27 18:22:23

我的global.axax:中有代码

protected void Application_Start()
{
    WindsorContainer = new WindsorContainer();
    WindsorContainer.Install(FromAssembly.InDirectory(new AssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath)));
    ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(WindsorContainer.Kernel));
//...
}

当我调试global.asax时,代码FromAssembly.InDirectory(newAssemblyFilter(AppDomain.CurrentDomain.RelativeSearchPath))会找到我的所有项目dll(有7个dll)。其中3个包含IWindsorInstaller接口的实现,例如:

class WindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        var services = AllTypes.FromThisAssembly().Where(type => type.Name.EndsWith("Service"));
        container.Register(services
            .WithService.DefaultInterfaces()
            .Configure(c => c.LifestyleTransient()));
        container.Register(Component.For<ISession>().ImplementedBy<AspnetSession>().
            LifeStyle.Transient);
        container.Register(Component.For<ICache>().ImplementedBy<AspnetCache>().
            LifeStyle.Transient);
    }
}

但当我设置断点时,只有一个安装程序被调用,另外两个被跳过。这很有趣,但我有另一个工作项目,来自我复制的代码。

温莎城堡罐头';在程序集中找不到安装程序

您的安装程序类应该是公共的。您当前的安装程序类没有访问修饰符,因此默认为internal-并且对Windsor不可见。Castle文档在此处指定:https://github.com/castleproject/Windsor/blob/master/docs/installers.md.

检查Project中的所有程序集名称->右键单击->属性。使用类型时。Name.EndsWith("Service")您的程序集名称和默认命名空间可能缺少单词(包括您正在执行的项目。例如WebAPI项目或UnitTest项目)。这就是为什么您无法获得所需的程序集。