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 3321612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:05:01+00:00 2026-05-17T23:05:01+00:00

I am making an app which supports multiple databases. The beerhouse architecture instantiates the

  • 0

I am making an app which supports multiple databases. The beerhouse architecture instantiates the correct class from the correct provider using the singleton below.

  static private ArticlesProvider _instance = null;
  static public ArticlesProvider Instance
  {
     get
     {
        if (_instance == null)
           _instance = (ArticlesProvider)Activator.CreateInstance(
              Type.GetType(Globals.Settings.Articles.ProviderType));
        return _instance;
     }
  }

I have the providertype stored into a custom section in my web.config and am trying to create a factory which instantiates the correct DAL class based on the set provider.

The above currently takes the whole namespace stored in the web.config, to the relevant DAL class and is a bit limited as it only creates instances of the ArticlesProvider. How can I make a generic factory, so I can pass in the providertype eg SqlServer and any class eg ArticleDAL, which I wish to instantiate?

Thank you in advance.

  • 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-17T23:05:02+00:00Added an answer on May 17, 2026 at 11:05 pm

    I would look into using a proper dependency injection framework, personally I like NInject. This will give you all the tools you need to break the dependency between your application and the underlying database.

    You register mappings with the framework, from interfaces to concrete types. These mappings could be in web.config, or in some configuration code in your application startup. The framework will instantiate the classes for you – injecting further dependencies if required.

    So you can ask for an instance of IArticleDAL, and if IArticleDAL requires an instance of IDbConnection to access a DB then NInject will automatically create one and pass it to the constructor of the implementation of IArticleDAL.

    Anyway – the documentation explains it much better… but in summary the code you’ve extracted above is just a primitive starting point for proper dependency injection.

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

Sidebar

Related Questions

i m making APP which do image proceesing using java SE.i want to check
I am making an App in which i have to play music from iPod
I am making a JavaScript app which shows the weather of several places. Using
I am making an app which basically presents data (from plist) to user in
I'm making an app which constantly receives Heart Rate from a bluetooth device in
I'm making an app which has a tableview and a DetailViewController. I'm using Apple's
I am making an app which contains fragments within tabs.In this whenever I try
I am Getting a weird problem. I am making an App which should run
I am making an app in which i need to implement calling emergency medical
I'm making an app in which I open a BrowserField and the user can

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.