1

を使用して OpenRasta の依存関係リゾルバーにいくつかのインスタンスを登録するとします。

resolver.AddDependencyInstance(IInterface, instance, DependencyLifetime.Singleton)

後でそのインスタンスを交換したい場合、たとえばデータベースから新しいデータを再読み込みする場合、resolver.AddDependencyInstance をもう一度呼び出すのは正しいことですか?

InternalDependencyResolver の実装を確認すると、問題ないようです。ただし、動作が定義されておらず(確認したopenrastaのソースで)、メソッドプレフィックス「Add」が異なる動作を示唆しているため、質問しています。

4

1 に答える 1

1

I wouldn't use Singleton if you have to swap the instance at some point. Use DependencyLifetime.Transient and have a constructor injection in the class where you need the new instance

于 2011-12-22T14:01:39.613 に答える