私は現在、Autofacを使用しているアプリケーションを持っています。 configファイルから登録するautofacを構造化しました。デフォルトの動作のxmlベースのオーバーライドの場合は、モジュールがロードされた後にです。Autofac XML設定とプロパティオーバーライドまたは存在しない場合は提供するか?
今、私は基本的な環境設定の束を持っています(実際には公共の自動プロパティのスルー)。このクラスはいくつかの設定に基づいてデフォルト設定を推測しようとしますが、アプリが実行する各環境がxml設定のこれらの設定を上書きするという考えがあります。
はここに私の問題だ:
以前、このシステムの開発では、物事は桃でした。 XML Configの入力を完全に無視しているようです。私はこれが壊れた原因が変わったかどうか分からないので、間違っていることを誰かが明白に指摘できると思っています。
私は設定ファイルがautofacによって読み込み/解析されていることを確認しました。ただ適用されません。
web.configファイル:
<autofac>
<files>
<file name="Config/Environment.config" section="autofac-common" />
<file name="Config/Environment.config" section="autofac-public" />
</files>
</autofac>
Environment.config:
<configuration>
<configSections>
<section name="autofac-common" type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/>
<section name="autofac-public" type="Autofac.Configuration.SectionHandler, Autofac.Configuration"/>
</configSections>
<!-- Common -->
<autofac-common>
<components>
<component type="MyApp.Web.Configuration.ServerConfiguration, MyApp.Web"
service="MyApp.Web.Configuration.IServerConfiguration, MyApp.Web">
<properties>
<property name="Host" value="beta.mysite.com" />
<property name="MediaHost" value="beta.media.mysite.com" />
</properties>
</component>
</components>
</autofac-common>
<!-- Web Site -->
<autofac-public>
<modules>
<module type="MyApp.Configuration.CachingModule, MyApp">
<properties>
<property name="Disable" value="true" />
</properties>
</module>
</modules>
</autofac-public>
</configuration>
コンテナ建築基準
var builder = new ContainerBuilder();
// Register Identifier so it's available to modules
builder.RegisterType<ServerIdentifier>()
.As<IServerIdentifier>()
.SingleInstance();
var container = builder.Build();
builder = new ContainerBuilder();
builder.RegisterModule(new CachingModule() { Disable = true });
builder.RegisterModule(new LoggerModule());
builder.RegisterModule(new InventoryModule());
builder.RegisterModule(new CatalogModule());
builder.RegisterModule(new WebModule(container));
// Override with settings from XML
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
builder.Update(container);
のAutofacのバージョンは2.3.2.632
です。.NET 3.5
コンテナビルディングコードを表示できますか?また、どのバージョンのAutofacを使用していますか? –
@Peter Lillevold:コンテナビルディングコードで更新されました。また、autofacバージョンも含まれています。私はautofacの頻繁な変更と一貫性のある*変更の変更を想定しています*バージョンを知ることは他のライブラリよりも重要です:) – Aren
「一貫性のある壊れた変更」を参照していますか? –