1

autofacによって解決される単純な依存関係で動作するasp.net mvc 4アプリケーションがあります。この場合の依存関係は IEmailSender であり、その実装は開発ビルド、テストビルド、本番ビルドに基づいて変更したいと考えています。たとえば、開発 (デバッグ) ビルドは 1 つの実装を使用してメールを送信しますが、本番環境では Amazon SES を使用してメールを送信します。

環境に基づいて global.asax ファイル内のコンテナーの依存関係を変更するベスト プラクティスの方法は何ですか? Web デプロイで web.config 変換を使用し、web.config 値を読み取って環境を判断し、環境に基づいてビルド構成を「切り替える」ことができることはわかっていますが、もっと良い方法があるのでしょうか?

4

1 に答える 1

2

I would recommend the way you have described using the web config and environment transforms, as this is its primary purpose - to determine behaviour in different environments. You may also end up with more environments that just debug (test) and release (production).

The alternative could be to use conditional build statements like [Conditional("DEBUG")]. I would not recommend this approach however as you run out of build configurations pretty quickly if suddenly you have a new environment.

于 2012-09-17T22:22:19.917 に答える