2017-03-13 1 views
1

私はちょうど私の正気を点検しています。これはsimpleinjector 3.3.2RegisterPerWebRequestは廃止されていますが、Lifestyle.Scopedを使用できますか?

Container.RegisterPerWebRequest<HttpContextBase>(() => 
{ 
    var context = HttpContext.Current; 
    if (context == null && Container.IsVerifying) return new FakeHttpContext(); 
    return new HttpContextWrapper(context); 
}); 


Container.Verify(); 

を使用しています私のコードです...

​​

RegisterPerWebRequestが廃止とマークされているしかし、私はこれが変化するのが正しい方法であるかどうかは100%を確認していません新しいコードベースを反映するコード。

Container.Options.DefaultScopedLifestyle = new WebRequestLifestyle(); 

//So we can inject HttpContextBase into any class 
Container.Register<HttpContextBase>(() => 
{ 
    var context = HttpContext.Current; 
    if (context == null && Container.IsVerifying) 
    return new FakeHttpContext(); 

    return new HttpContextWrapper(context); 
}, Lifestyle.Scoped); 

ので、私の質問は、「私はRegisterPerWebRequestを置き換えるためにLifestyle.Scopedを使用すべきとあるように私はまだコードを使用することができますか?


Judging by the docs I should be doing it right

答えて

2

あなたが示したコードが正しいです。Container.Register<T>(Func<T>, Lifestyle.Scoped)置き換えContainer.RegisterPerWebRequest<T>(Func<T>)

関連する問題