【问题标题】:Castle Windsor can't find installers in assembliesCastle Windsor 在程序集中找不到安装程序
【发布时间】:2012-02-04 14:57:33
【问题描述】:

我的 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);
    }
}

但是当我设置断点时,它只调用了 1 个安装程序,跳过了 2 个其他安装程序。 这很有趣,但我从我复制的代码中得到了另一个工作项目。

【问题讨论】:

    标签: c# asp.net-mvc asp.net-mvc-3 castle-windsor windsor-3.0


    【解决方案1】:

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

    【讨论】:

    • 发生在我们所有人身上,一直如此:)
    • 嗯,文档明显移动了,我会更新链接。
    【解决方案2】:

    从 Project->Right Click->Properties 中检查所有程序集名称。使用 type.Name.EndsWith("Service") 时,您的程序集名称和默认命名空间可能缺少单词(包括您正在执行的项目。例如 WebAPI 项目或 UnitTest 项目)。这就是您无法获得所需程序集的原因。

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多