I've following code:

public class TestClass
{
    public string Foo { get; set; }
    public ITest<string> Test { get; set; }
}

[Convertible]
public interface ITest<T>
{
    T Param { get; set; }
}

[Convertible]
public class Test<T> : ITest<T>
{
    public T Param { get; set; }
    public string OtherParam { get; set; }
}

And I'd like to use it

WindsorContainer container = new WindsorContainer(new XmlInterpreter());
var t = container.Resolve<TestClass>();

I don't want use Fluent configuration but xml-configuration. Also I'd like to escape explicit registration of components for ITest. It's lloks like that it can be configured with only one component registration (TestClass) and all parameters can be provided in in <parameters> node. But currently I failed to create working configuration, it creates null TestClass object or TestClass with Test property set to null.

My configuration:

  <component id="Service.Main"
         type="ConsoleApplication1.TestClass"
         lifestyle="transient">
    <parameters>
      <foo>foo string</foo>
      <Test>
        <Param>param string</Param>
        <OtherParam>sdgsdfgdf</OtherParam>
      </Test>
    </parameters>
  </component>

Maybe someone can advise right configuration? Thnx

有帮助吗?

解决方案

So, I got sources for 3.2.0 version. Add simple console application and check different versions with debugging.

Here is working solution:

  <component id="Service.Main"
         type="ConsoleApplication1.TestClass"
         lifestyle="transient">
    <parameters>
      <foo>foo string</foo>
      <Test>
        <parameters type="ConsoleApplication1.Test`1[[System.String, mscorlib]], ConsoleApplication1">
          <Param>param string</Param>
          <OtherParam>sdgsdfgdf</OtherParam>
        </parameters>
      </Test>
    </parameters>
  </component>

Important notes:

  1. We should use for subsequent complex properties, otherwise it can't "see" all list of parameters. It get only first child: ConfigurationParametersInspector.cs, line 58
  2. We should explicitly set the type of parameter that represented by property with interface type. We can expect that type attribute should be used for &ltTest> node but in fact, only child XML nodes passed to the method that choose type for property.

Anyway configuration checked with 3.2.0 and it works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top