持っている(DelegateHandler
私は仮定)を使用すると、一般的にパーHTTPリクエストまたは過渡としてITest
を登録しますので、それが不可能な場合は、依存関係をラップサービスの寿命は常に、同等またはその依存関係のそれよりも短くする必要がありますプロキシでのあたりのHTTPリクエスト寿命:
public class Foo
{
Func<IEnumerable<ITest>> _resolutionFunc;
ITest _test;
public Foo(Func<IEnumerable<ITest>> resolutionFunc)
{
_resolutionFunc=resolutionFunc;
}
private void ResolveFuncToInstance()
{
_test=_resolutionFunc().First();
}
}
私たちがやっていることは、すべてのたITestを解決しますデリゲートをご提供するためにUnityに求めている:
// Proxy
public class DelegateHandlerProxy : IDelegateHandler
{
public Container Container { get; set; }
// IDelegateHandler implementation
void IDelegateHandler.Handle()
{
// Forward to the real thing by resolving it on each call.
this.Container.Resolve<RealDelegateHandler>().Handle();
}
}
// Registration
container.Register<IDelegateHandler>(new InjectionFactory(
c => new DelegateHandlerProxy { Container = c }));
ありがとう、非常に良い答え! –
一般的なソリューションに変換するのはクールですが、それは不可能です) –