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!

Thanks.

Jun 3, 2011 at 11:14 AM

Hi,

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.
entlib.support@avanade.com

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

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

<containers>
  <container name="">
    <registerByPolicy assembly="xxx.Web" policy="ImplementsInterface" name="" />
 </container>
 <container name="Services">
   <registerByPolicy assembly="xxx.Services.Contracts" name="" policy="ImplementsInterface">
     <constructor>
       <param name="address" type="EndpointAddress">
         <appSettingPolicy key="EndpointBase" format="{0}{Name}.svc" typeConverter="StringToEndpointAddress" />
       </param>
     </constructor>
   </registerByPolicy>
 </container>
<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>
<container name="DataSources">
  <registerByPolicy assembly="xxx.Data" policy="ImplementsInterface" name="" /> 
</container>
  <containers>
</unity>

I used the Unity AutoMapper project on codeplex for my original inspiration, but heavily adapted for our purposes

http://autoregistration.codeplex.com/
Jun 7, 2011 at 2:13 AM
Edited Jun 7, 2011 at 2:13 AM

Hi Both,

Thank you for your advice. 

Best Regards!