2013-02-28 44 views
1

我想用Ninject而不是Funq來使用ServiceStack。我有以下幾點: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>(); 
    } 
} 

然後我的配置方法中:

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) 
{ 

} 

回答

3

的代碼完全匹配the documentation一個細微的差別。您必須使用ServiceStack.Configuration.IContainerAdapter而不是您自己的IContainerAdapter

刪除您的實施,添加對ServiceStack.Configuration的引用,你應該沒問題。

相關問題