1

I have an C# dll project for which I have to store the runtime settings in an external XML file, and this dll will be used in an ASP.NET/ASP.NET MVC application for which I also have to store the runtime settings in a external file.

Which IoC container can be used to create an object with the runtime settings loaded from a specific external file (or app.config/web.config), and also works for web applications running in medium trust? Any howto/tutorial would be greatly appreciated.

So far I've found only this articles:

Update

I'm sending mails from my dll to a variable number of SMTP servers, based on the current record type. For type A I'm using a given SMTP server+port, for type B I'm using an alternate set of server+port values. Of course, I want to be able to modify those values after deployment, so I store them in a XML file.

If I'm storing the SMTP settings as a SMTPConfiguration class with 2 properties (SMTPServer as String and SMTPPort as Int32), is it possible to return from an IoC container the required object based on the given record type, and what is the best way to read the runtime settings in order to build the returning object?

Update2

Let's say I'm storing in the configuration file the following parameters: ASMTPServer, BSMTPServer, ASMTPPort, BSMTPPort. I can use Castle DictionaryAdapter to read all those settings as properties of an AppConfiguration class.

What is the recommended method to specify that the required SMTPConfiguration class should use ASMTPServer and ASMTPPort values if I'm using a type A record as a parameter (and should use BSMTPServer and BSMTPPort values if I'm using a type B record as a parameter) ? Also, how can I specify that the AppConfiguration is required in this process?

alexandrul
  • 12,856
  • 13
  • 72
  • 99
  • Windsor can load external files... you just write new WindsorContainer(new XmlInterpreter("path to your file")); or something like this. I'm writing this from memory so I may get the class names wrong, but you get the idea. is that what you're looking for? – Krzysztof Kozmic Oct 22 '09 at 14:16
  • @Krzysztof Koźmic: not really, I'm keeping my application settings as a class (with properties like smtp name, port, mail address and so on), and i would like to use the same IoC container for both my application as a DI and for loading my settings from an external configuration file. – alexandrul Oct 22 '09 at 16:48
  • I'm not sure I understand you correctly - if you want to load a configuration from existing object you may write custom IResource that inherits from AbstractStreamResource, deserializes the object to the memory and expose them for reading as a stream. If your object has different shape than config file, you can write custom IConfigurationStore. – Krzysztof Kozmic Oct 23 '09 at 08:25
  • Actually let's invert the question - where does your configuration object come from? Maybe you can feed the settings to the container and create that object from there? Can you give an example of how it looks like and how you use it (both the object, and the config file)? – Krzysztof Kozmic Oct 23 '09 at 08:29
  • @Krzysztof Koźmic: thank you for your time and patience, I have updated the question. – alexandrul Oct 23 '09 at 10:01