Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuration reading from XML file that is not app.config #386

Closed
alexmg opened this issue Jan 22, 2014 · 10 comments
Closed

Support configuration reading from XML file that is not app.config #386

alexmg opened this issue Jan 22, 2014 · 10 comments

Comments

@alexmg
Copy link
Member

alexmg commented Jan 22, 2014

From estrada.raphael on August 21, 2012 23:55:04

What steps will reproduce the problem? 1. Call ctor of ConfigurationSettingsReader
2. Pass custom xml file (see below) as file paramter
3. Autofac complains that it cannot find the section

I would like to see a SettingsReader that can read custom XML (just a plain vanilla autofac section, no app.config specific schema) to configure autofac. What version of Autofac are you using? On what version of .NET/Silverlight? .NET 4.0, version 2.6.3.862

I suggest providing an XmlSettingsReader that does not look for a specific section, but just reads the entire file into a SectionHandler. Given some restrictive accessors (internal types, private _sectionHandler field on ConfigurationSettingsReader) it's tough for me to do this in my own project/namespace (I need to use vanilla autofac binaries for various reasons).
I tried to derive from ConfigurationSettingsReader, it seems if I managed to deserialize the SectionHandler (tricky since ConfigurationManager is coupled to app.config...) and assign the _sectionHandler via reflection. My main issues were the deserialization part. It's probably much easier for you guys.

the schema of the file I'd like to load contians only autofac info, nothing with regards to app.config (i.e. no root, and no )

// autofac.config


...

If I find some down time I'll see if I can do it myself and submit a patch, but it would be great if you guys could do this.

Thanks for the excellent tool!

Original issue: http://code.google.com/p/autofac/issues/detail?id=386

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From estrada.raphael on August 21, 2012 06:55:25

Sorry, this should be an enhancement, not a defect

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on September 20, 2012 09:21:15

Summary: Support configuration reading from XML file that is not app.config
Labels: -Type-Defect Type-Enhancement

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on September 21, 2012 09:38:25

Labels: Module-Configuration

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on September 28, 2012 10:16:03

I have something for this working in the 3.0 code. As soon as I push it to trunk, I'll update this issue as fixed.

The new class to look for is XmlFileReader.

builder.RegisterModule(new XmlFileReader("path/to/config.xml"));

It uses the same XML schema as the regular configuration settings but doesn't require the stuff that standard .NET configuration requires.

Status: Started
Owner: travis.illig

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From travis.illig on September 28, 2012 10:46:12

Pushed to trunk. When 3.0 releases, you'll see the new bits.

Status: Fixed

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From estrada.raphael on September 29, 2012 09:06:29

thanks, you rock.

I'll give it a try when I get a chance.

@alexmg
Copy link
Member Author

alexmg commented Jan 22, 2014

From estrada.raphael on July 09, 2013 03:44:52

I know it's been ages, but this seems to be working, so thanks :-)

@alexmg alexmg closed this as completed Jan 22, 2014
@kbrow20
Copy link

kbrow20 commented Jun 29, 2021

Is the XMLFileReader class been depreciated? I can't seem to find it any longer.

@tillig
Copy link
Member

tillig commented Jun 29, 2021

Read the docs.

@kbrow20
Copy link

kbrow20 commented Jun 29, 2021

Ok so you want this now?

builder.RegisterModule(new ConfigurationModule(new ConfigurationBuilder()
.AddXmlFile(Path.Combine(BinaryPath, $"{ApplicationName}.config"))
.Build()));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants