我试图在ServiceStack中使用MEF作为ContainerAdapter(https://github.com/ServiceStack/ServiceStack/wiki/The-IoC-container)。在ServiceStack服务中使用MEF
我做了ContainerAdapter:
internal class MefIocAdapter : IContainerAdapter
{
private readonly CompositionContainer _container;
internal MefIocAdapter(CompositionContainer container)
{
_container = container;
}
public T TryResolve<T>()
{
return _container.GetExportedValue<T>();
}
public T Resolve<T>()
{
return _container.GetExportedValueOrDefault<T>();
}
}
,注册它像这样:
public override void Configure(Container container)
{
container.Adapter = new MefIocAdapter(_mefContainer);
}
由RegisterService(System.Type的,字符串)函数注册服务之后,我越来越MEF的异常。它找不到出口:
ContractName ServiceStack.Auth.IAuthSession
RequiredTypeIdentity ServiceStack.Auth.IAuthSession
我误解了一些东西吗?
为什么Funq要求适配器容器解决内部ServiceStack的依赖性?
funq会使用MEF来实例化我的服务吗? (如果没有,有没有像服务工厂?)
P.S.当我删除container.Adapter分配它的作品(但我的MEF依赖项为空)。
谢谢!多么愚蠢的错误...我必须将funqContainer.CheckAdapterFirst设置为true才能让我的服务由MEF实例化,因为服务也在funq容器中注册,并且我的MefAdapter尚未被调用。 – smokeing