c# - Autofac XML Configuration & Properties Override or Provide if not present? -
i've got application using autofac @ moment. i've structured autofac register config file after modules loaded in. (for xml-based override of default behaviour).
right i've got class bunch of basic environmental settings (a slew of public auto-properties really). class tries guess default configuration based on settings, idea each environment app runs under override these settings in xml config.
here's problem:
earlier in development of system, things peachy. now seems ignoring input of xml configs. unsure changed caused broken, i'm hoping can point out obvious doing wrong.
i have verified config file getting read/parsed autofac, not applied.
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> container building code
var builder = new containerbuilder(); // register identifier it's available 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 settings xml builder.registermodule(new configurationsettingsreader("autofac")); builder.update(container); autofac version 2.3.2.632 .net 3.5
the problem in <files> section. since handled fileelementcollection, configuration class inheriting namedconfigurationelementcollection class , using name property key value, multiple entries must have unique name values.
since referring same name twice, first entry referring autofac-common section overwritten second entry. thus, service never registered, cachingmodule.
i cannot whether new behavior on autofac's part or not, far can tell source, fileelementcollection class introduced in 2.0 , haven't changed logic since then. have referenced different .config files earlier?
Comments
Post a Comment