迁移到Windsor 3后,从xml注册不同的实现,并且一个接口的代码失败

时间:2012-04-02 15:25:00

标签: c# castle-windsor windsor-3.0

我们正在将一个稳定的项目从Castle Windsor 2.5.2迁移到3.0。

我们使用混合xml / api注册。切换到3.0后,通过ctor注入并在xml中定义的参数不再能够解析。

举例说明:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
  <properties>
    <frontEnd.url>http://site.com</frontEnd.url>
    <admin.email>admin@site.com</admin.email>
  </properties>

  <components>
    ...
    <component id="ServicesBootstrapperAction"
   service="SomeNS.Startup.IBootstrapperAction"
        type="SomeNS.Service.ServicesBootstrapperAction, Project-Service"
        >
      <parameters>
        <frontEndUrl>#{frontEnd.url}</frontEndUrl>
        <adminEmail>#{admin.email}</adminEmail>
        <prohibitedLogins>Assets/prohibited-logins.txt</prohibitedLogins>
      </parameters>
    </component>
    ...
  </components>
</configuration>

注册:

        _container.Install(
            Castle.Windsor.Installer.Configuration.FromXmlFile("project.common.config"),
            Castle.Windsor.Installer.Configuration.FromXmlFile(String.Format("project.{0}.config", RuntimeEnvironment))
            );

尝试解决此组件后,我们得到:

'SomeNS.Service.ServicesBootstrapperAction' is waiting for the following dependencies:
- Parameter 'frontEndUrl' which was not provided. Did you forget to set the dependency?
- Parameter 'adminEmail' which was not provided. Did you forget to set the dependency?
- Parameter 'prohibitedLogins' which was not provided. Did you forget to set the dependency?

同样,这是与2.5完美配合的东西,所以我想这可能是一些无证(或错过/不被我们理解)破坏变化。

鉴别诊断,任何人?

更新: 我发现了问题并找到了解决方法。我不喜欢它,但它有效。

对于所有好奇的人,这里是说明问题的项目的链接: https://docs.google.com/open?id=0B7XFrOzGfmirSldZUmRQeU9SZDZZVnV5UGhGaGhsUQ

随意告诉我,我错了,我应该使用其他一些漂亮的解决方案(什么?)。

2 个答案:

答案 0 :(得分:0)

尝试从节点名称中取出句点。这应该没关系,但这是我唯一可以看作潜在问题的东西(主要是因为除了XAML之外,我没有在XML节点名称中看到过多使用句点)。

答案 1 :(得分:0)

我认为关闭此问题是公平的,因为我找到了原始问题的解决方法。

我真正的问题是我有一个接口的几个实现(并且需要它们全部)。但是,一些实现需要参数(简单值),这些参数自然被移动到xml配置文件,而其他实现则使用代码中的约定进行注册。

现在,为了避免双重注册我在3.0之前使用过.Unless(container.Kernel.HasComponent),现在已经过时,但编译得很好!

令人惊讶的是,.Unless(t =&gt; container.Kernel.HasComponent(t.Name))和以前一样很棒!

我确信有一个解释,但我想不出任何。

我真的很喜欢Castle并喜欢使用它。但45 kb的突破性变化并不酷,对不起家伙们。