直到最近我用AutoFac其中有方法AsImplementedInterfaces()
这确实StructureMap:注册为实现接口,如在AutoFac
注册类型提供其所有的公共接口作为服务(不包括IDisposable接口)。
该装置(例如,服务)我有一些基本接口和用于每concerte服务级
接口请参见下面的简单的代码:
public interface IService {}
public interface IMyService: IService
{
string Hello();
}
public class MyService: IMyService
{
public string Hello()
{
return "Hallo";
}
}
// just a dummy class to which IMyService should be injected
// (at least that's how I'd do it with AutoFac.
public class MyClass
{
public MyClass(IMyService myService) { }
}
基本上我要注入我的服务界面(可以这么说)而不是具体的服务。
现在我必须使用StructureMap,但我很难找到我需要的东西。 有AddAllTypesOf<T>
但这会注册具体类型。
这是甚至有可能与StructureMap,如果是的话如何?