Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:07:18+00:00 2026-05-26T04:07:18+00:00

Say I have an application with the following structure. // ASP.NET MVC (Web Project)

  • 0

Say I have an application with the following structure.

// ASP.NET MVC (Web Project)
// Service/Business Layer (Class Library)
// DAL (Class Library)

Initially I wanted to use an App.config file in the DAL class library which would hold app settings like this:

<appSettings>
   <add key="DAL-Assembly" value="DAL.LinqToSql.DataContexts"/>
   <add key="DAL-Type" value="DAL.LinqToSql.DataContexts.MyDataContext" />
</appSettings>

And then I would use a factory to create the data context using reflection

public static DataContext GetContext()
{
    string assembly = ConfigurationManager.AppSettings("DAL-Assembly");
    string type = ConfigurationManager.AppSettings("DAL-Type");

    Assembly a = Assembly.Load(assembly);
    return (DataContext)a.CreateInstance(type);
}

The problem is that now I understand that a Class Library has to use the configuration file of the calling application. Which means that it would be looking in the presentation for the app.config or web.config – which doesn’t seem right.

In this DAL situation, what is the best way to keep the concrete DataContext specification contained in the DAL layer, without having to rebuild each time it is changed? Or even in a broader sense, the best way to keep configuration external in the DAL layer?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:07:19+00:00Added an answer on May 26, 2026 at 4:07 am

    I would try and keep the configuration separate and actually inject it into the layer in question. So in your DAL layer I would perhaps have a factory class that dealt out the particular data gateways and this factory would take an IDataAccessConfiguration parameter in its default constructor. Then you could set static properties in a local configuration class or pass a local copy of the interface into a context when creating it. Example :

    public interface IDataAccessConfiguration
    {
        string Assembly { get; }
        string Type { get; }
    }
    
    public sealed class DataAccessfactory
    {
        private IDataAccessConfiguration Config { get; set; }
    
        public DataAccessfactory(IDataAccessConfiguration config)
        {
            this.Config = config;
        }
    
        public ISomeDataContext GetSomeDataContext()
        {
            return new SomeDataContext(this.Config);
        }
    }
    
    public class SomeDataContext : ISomeDataContext
    {
        private IDataAccessConfiguration Config { get; set;}
    
        public SomeDataContext(IDataAccessConfiguration config)
        {
            this.Config = config;
        }
    
        private DataContext GetDataContext()
        {
            Assembly a = Assembly.Load(this.Config.Assembly);       
            return (DataContext)a.CreateInstance(this.Config.Type);  
        }
    }
    

    Then, when you actually want to get the settings from the particular app.config file you can do it in the standard manner, create a concrete class that implements IDataAccessConfiguration and set its members with the values from the config file and pass that class around. See this link for a question I asked that relates to this : Best way of injecting application configuration

    Is this the sort of thing you are looking for?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following structure in my ASP.NET MVC 3 application. Items
Let's say I have the following threading in my Rails web application: class MyController
I have following structure of web application, for which I'm automating testing: <em unselectable=on
My application has the following project structure: There is the Business Logic project and
Lets say I have following DB structure: and my application needs to show the
Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input
How is the app.config binding in .Net? Let's say if I have an application
I'm using Iirf v2.0 . I have the following directory structure: / /library /library/index.php
My application problem is the following - I have a large structure foo. Because
I have a weird issue. Say you have the following: Application.ThreadException += something; try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.