如何为其所有接口注册泛型类型

时间:2014-08-06 22:32:34

标签: structuremap

我有一堆看起来像这样的课程

public class SlideDefinitionAntiCorruption : 
        ICommandHandler<SlideAssignedToSlideset>, 
        ICommandHandler<SlideRemovedFromSlideset> {

我希望所有这些界面都能注册。

我目前有

        ObjectFactory.Configure(x => x.Scan(s => {
            s.TheCallingAssembly();
            s.WithDefaultConventions();
            s.RegisterConcreteTypesAgainstTheFirstInterface();
            s.AddAllTypesOf(typeof(ICommandHandler<>));
        }));

这会将其注册到第一个界面,而不是其他界面。

那我该怎么做?

1 个答案:

答案 0 :(得分:2)

请注意: [Obsolete("ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work")]

ConnectImplementationsToTypesClosing接口的方法IAssemblyScanner 你可以像以下一样使用它:

new Container(x => {
    x.Scan(s => {
        s.Assembly(Assembly.GetEntryAssembly());//by e.g. get entry assembly for scan
        s.ConnectImplementationsToTypesClosing(typeof(ICommandHandler<>));
    });
});