我正在尝试在ServiceStack中使用Ninject而不是Funq。我有以下几点:
public interface IContainerAdapter
{
T Resolve<T>();
T TryResolve<T>();
}
public class NinjectIocAdapter : IContainerAdapter
{
private readonly IKernel kernel;
public NinjectIocAdapter(IKernel kernel)
{
this.kernel = kernel;
}
public T Resolve<T>()
{
return this.kernel.Get<T>();
}
public T TryResolve<T>()
{
return this.kernel.TryGet<T>();
}
}然后在我的Configure方法中:
public override void Configure(Funq.Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
IKernel kernel = new StandardKernel();
container.Adapter = new NinjectIocAdapter(kernel);
//Set MVC to use the same Funq IOC as ServiceStack
//ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
}但我得到以下错误:
Cannot implicitly convert type 'NinjectIocAdapter' to 'ServiceStack.Configuration.IContainerAdapter'.
我也不确定是否必须取消注释这行代码来设置MVC来使用Funq IoC?我已经把它注释掉了,因为我将使用Ninject。对吗?
我假设一旦所有的工作都成功了。我可以简单地在里面注册任何依赖项:
private static void RegisterServices(IKernel kernel)
{
} 发布于 2013-02-28 20:27:46
代码与the documentation完全匹配,但有一个细微的区别。
您必须使用ServiceStack.Configuration.IContainerAdapter而不是您自己的IContainerAdapter。
删除你的实现,添加一个对ServiceStack.Configuration的引用,你就应该没问题了。
https://stackoverflow.com/questions/15134286
复制相似问题