2017-01-29 11 views
1

ServiceStackと異なるIOCコンテナLightInjectをデフォルトよりも使用するため、依存クラス(ServiceStackController、Serviceなど)が正しいゲートウェイを取得するために登録する必要があります。IServiceGatewayFactory IOC登録

例:

LightContainer.Register<ServiceStack.Web.IServiceGatewayFactory>(x => new ApiServiceGatewayFactory(), new PerRequestLifeTime()); 
LightContainer.EnableMvc(); 
//later 
public class HomeController : ServiceStackController 
    { 
    public HomeController() 
    { 
     // is null 
     Gateway.Send<SpeakerRequest>(new SpeakerRequestReq() { Id= new Guid("deda0678-cea5-4c23-b6b0-af2455ed6c66") }); 

    } 

私はこれがアップ有線取得するために登録する必要があります他に何かわからないので、コントローラ上のGatewayプロパティがまだnullですか?

答えて

1

ServiceGatewayはServiceStackのAppHost.Configure()に登録する必要がありますが、当然​​まで解決されるはずです。

あなたがオーバーライドすることでLightContainerから直接工場を解決しようとすることができます解決していない場合:

public virtual IServiceGateway GetServiceGateway(IRequest req) 
{ 
    var factory = LightContainer.GetInstance<IServiceGatewayFactory>(); 
    return factory != null ? factory.GetServiceGateway(req) 
     : Container.TryResolve<IServiceGateway>() 
     ?? new InProcessServiceGateway(req); 
} 
+0

私は仕事にこれを取得することになった、しかし現在IRequestをキャプチャドキュメントの状態は、 'ゲートウェイ工場のインスタンスを作る非シングルトンとして使用するのに適しているので、ReuseScopeに登録する必要があります.Noneスコープで、新しいインスタンスが毎回解決されるようにしてください: ' – lucuma

+0

@lucumaドキュメントが正しく、私の答えが更新されました。 – mythz

関連する問題