0

我知道我可以为一个组件注册一个类型,如下所示:

<component 
    id="myservice"
    service="MyServices.IService"
    type="MyServices.Impl.Service1" />

想象一个场景,我有一个类,它需要一个 IService 数组,如下所示:

public class MyClass
{
    public MyClass(IService[] services) { ... }
}

例如,如何使用 XML 配置为 IService 组件注册 Service1、Service2 和 Service3?

4

1 回答 1

0
<component 
    id="myservice1"
    service="MyServices.IService"
    type="MyServices.Impl.Service1" />
<component 
    id="myservice2"
    service="MyServices.IService"
    type="MyServices.Impl.Service2" />
<component 
    id="myservice3"
    service="MyServices.IService"
    type="MyServices.Impl.Service3" />

或者,如果您想更紧凑:

<component service="IService" type="Service1" />
<component service="IService" type="Service2" />
<component service="IService" type="Service3" />
于 2012-04-28T04:23:10.540 回答