Using External Configuration File for Enterprise Library Configuration

November 15, 2009

one comment

Using External Configuration File for Enterprise Library Configuration


One of the things Using External Configuration File for Enterprise Library Configuration
that I always do when
I’m using Enterprise
Library
is to separate
its configurations to
external configuration file.
The reason is very obvious – using Enterprise Library makes
configuration files very crowded. Since this is the case, the
configuration files become unmanageable and then its time to
separate the Enterprise Library’s configurations from other
configurations.


How to Use external Configuration File for Enterprise Library Configuration?


It is very simple to separate the Enterprise Library configurations
to another external file.


Step 1
Create a new configuration file in the solution which is going to
hold the Enterprise Library configurations. In my solution I added
a new EL.config file in the root of the project along side for the
web.config.


Step 2
From Enterprise Library Configuration Tool add a new Configuration
Sources
node.
Configuration Sources Node 


Step 3
In the node add a new File Configuration Source with
the name you want to give the file.
Add New File configuration Source


 


Give it a relevant name such as EntLib Configuration Source.


Step 4
In the properties of the created File Configuration Source add the
path to the file which can be full path or relative path. I prefer the
relative path.
Configure The File Configuration Source


 


Since my file sits in the root of the project I only have to write
its name and it will be given a relative path. If for example I put it
in a Configuration directory I’ll have to write Configuration/EL.config.


Step 5
Make the new File Configuration Source the selected source and
that is it.


After doing so all the Enterprise Library configurations
will sit in the file configuration source and not in your web.config
enabling the separation of Ent-Lib configurations from the application
configurations. Also when you’ll open the web.config (or app.config) in
Enterprise Library Configuration Tool it’ll show the Enterprise Library
configurations and enable making changes which will be saved in the
other EL.config automatically for you.


Summary


In the post I showed how to separate the Enterprise Library configurations
to external file. This is done to increase manageability of configuration files.


DotNetKicks Image

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

one comment

  1. sachinJanuary 5, 2010 ב 8:15

    how to use this file in the application

    Reply