Sunday, 15 September 2013

C#.NET: How to create/use Configuration File for Infrastructure Layer (Class Library) Project in Domain-Driven Model

C#.NET: How to create/use Configuration File for Infrastructure Layer
(Class Library) Project in Domain-Driven Model

In my Domain Driven Layers, Infrastructure Layer Project is class library
Project which needs to use a configuration file for not only connecting to
database but also to create Repositories and Entities. However, the links
(mentioned at the end of post state that class library project cannot have
a configuration file (I think, class library cannot have a app.config).
My Question is that if not then how to create and use a configuration file
for my Infrastructure Layer (Class Library) Project ? under which Project
and what should be the naming convention ?
DETAIL:
I am following a book on Domain Driven Design in C#.NET. In this model
(Visual Studio Solution), there four layers (each project in Visual Studio
as layer) named below:
1) Presentation Layer Project (WPF, not .NET class library) 2) Application
Layer Project (.NET class Library) 3) Model Layer Project (class Library)
4) Infrastructure Layer (.NET class Library)
Infrastructure Layer Project (as .NET clas Library) needs to use a
configuration file, in order to:
A) Create Repository (using Repository Factory), B) Create Entities (using
EntityFactoryBuilder), C) Connecting to database.
For this i created configuration file under the project
"ProjectName.Infrastructure" as "ProjectName.Infrastructure.config" by
setting its property (using Visual Studio) "Copy to Output Window" as
"CopyAlways".
However, according to some posts (links at the end):
"a class library project (like my "Infrastructure Layer Project") cannot
have a configuration file (application configuration file OR app.config
file) instead a calling application should supply/provide configuration
file and that class library use this provided file".
Links ( That i researched on):
How access a custom config from my class library application?
and
http://msdn.microsoft.com/en-us/library/ms229689.aspx

No comments:

Post a Comment