我不相信你能在结构图中做到这一点。可以将要查找的单独的构造函数行为拉入适配器类中吗?然后,您的代码可以依赖于必要的适配器类。
public class FirstBehavior : IBehavior
{
private WrappedClass _wrappedClass;
public FirstBehavior()
{
_wrappedClass = new WrappedClass(<first constructor>)
}
}
public class SecondBehavior : IBehavior
{
private WrappedClass _wrappedClass;
public SecondBehavior()
{
_wrappedClass = new WrappedClass(<second constructor>)
}
}
[TestFixture]
public class Test
{
[Test]
public void configure_container()
{
var container = new Container(config =>
{
config.For<IBehavior>().Use<FirstBehavior>().Named("first");
config.For<IBehavior>().Use<SecondBehavior>().Named("second");
});
container.GetInstance<IBehavior>("first").ShouldBeOfType(typeof(FirstBehavior));
container.GetInstance<IBehavior>("second").ShouldBeOfType(typeof(SecondBehavior));
}
}