The XML configuration is more flexibility than the Program Configuration ?

Jun 3, 2011 at 9:26 AM

Hi All,

I have a doubt that Whether  the XML configuration is more flexibility than the Program configuration.

Base on my realize  if my application is base on the programmatic configuration and once I change the mapping relationship, I have to change my code.

But I could just change config file base on the XML configuration.  

If so What is the strength to  the programmatic configuration?

What are the strengths and weakness between the XML configuration and Programmatic configuration?

Is there any mistake for me? Any help will be appreciate!


Jun 3, 2011 at 11:14 AM


My personal take on this is, it's still depends on your requirements, since both have advantages and disadvantages to consider. To shed you some light regarding this topic, I highly recommend you to read the documentation that can be found here. Hope this helps. :)


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.

Jun 5, 2011 at 11:42 PM

personally I use both to achieve my setup

I have extended the XML configuration to use a registry by policy system.  The policy extensions then use the programatic API to configure, using reflection to discover types that make various naming policies, like ImplementsInterface

eg class MyType : IMyType { }  -> container.Register<IMyType, MyType>()

My test systems use the programatic API to override default registrations to inject mocks for both up and down stream dependancies.


I started using the XML configuration only, but the size of the configuration file grew very large as every type had to be represented ( we have well over 150 types to configure ), so using both alias and register, you're looking at a 400 line file.

So my config looks like

    <sectionExtension type="xxx.Practices.Unity.ConfigurationExtensions, xxx.Core" />
    <sectionExtension type="xxx.ServiceModel.ConfigurationExtensions, xxx.ServiceModel" />

  <container name="">
    <registerByPolicy assembly="xxx.Web" policy="ImplementsInterface" name="" />
 <container name="Services">
   <registerByPolicy assembly="xxx.Services.Contracts" name="" policy="ImplementsInterface">
       <param name="address" type="EndpointAddress">
         <appSettingPolicy key="EndpointBase" format="{0}{Name}.svc" typeConverter="StringToEndpointAddress" />
<container name="WCFHosts">
  <registerByPolicy assembly="xxx.Services"   policy="ImplementsInterface" name="" />
  <registerByPolicy assembly="xxx.Business"   policy="ImplementsInterface" name="" />
  <registerByPolicy assembly="xxx.Exceptions" policy="ImplementsInterface" name="" />
<container name="DataSources">
  <registerByPolicy assembly="xxx.Data" policy="ImplementsInterface" name="" /> 

I used the Unity AutoMapper project on codeplex for my original inspiration, but heavily adapted for our purposes
Jun 7, 2011 at 2:13 AM
Edited Jun 7, 2011 at 2:13 AM

Hi Both,

Thank you for your advice. 

Best Regards!