私はMVC3サイトを構築しており、Springを使用してWebサービスアダプターのランタイムインジェクションを提供し、実際の取引を呼び出す代わりに模擬サービス呼び出しをスタブできるようにしたいと考えています。
var ctx = ContextRegistry.GetContext();
var serviceAdapter = (IServiceAdapter) ctx[Constants.C_ServiceAdapter];
...
serviceAdapter.doSomething();
私は以前、シングルトンが「false」ではないSpringスレッドセーフに悩まされていたので、Springソースを調べて、上記がスレッドセーフであることを再確認しました。
ソースはコメントでこれを持っています:
/// A singleton implementation to access one or more application contexts. Application
/// context instances are cached.
/// </p>
/// <p>Note that the use of this class or similar is unnecessary except (sometimes) for
/// a small amount of glue code. Excessive usage will lead to code that is more tightly
/// coupled, and harder to modify or test. Consider refactoring your code to use standard
/// Dependency Injection techniques or implement the interface IApplicationContextAware to
/// obtain a reference to an application context.</p>
私の質問:なぜこれを使用するのは賢明ではないのですか?ボイラープレートが2列あるだけで必要ないのでしょうか。AFAIKまだ、構成で最終的に作成されるオブジェクトを宣言しているので、それがどのように緊密に結合されるのかわかりませんか?
注:Spring.Web dllを使用して、構成を介してすべてのDIを実行するというルートをたどりたくはありません。
どうもありがとうダンカン