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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:06:27+00:00 2026-05-28T16:06:27+00:00

Do you see any benefit in injecting the database connnection string from the Global.asax.cs

  • 0

Do you see any benefit in injecting the database connnection string from the Global.asax.cs
class in ASP.NET MVC compared to the method in reading the connection string from a BaseDataProvider class accessing the app.config file?

  • 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-28T16:06:29+00:00Added an answer on May 28, 2026 at 4:06 pm

    I’d prefer to inject any objects needed using constructor injection (whenever possible).

    One small advantage I see is transparency regarding a class’s dependencies.

    For example, if you try to instantiate a class in a test harness (while doing integration testing):

    • in the first case (constructor injection) you immediately see that it needs a connection string and provide one
    • in the second case you instantiate the class (perhaps using a default constructor) and after some trial & error discover that it depends on the ConnectionString property being set

    Update:
    Another advantage of the constructor injection approach is that it decouples the class itself from the mechanism of getting the connection string from the app.config.

    This could enable in the future scenarios that you don’t even think about right now.

    For example, in a project I currently work on I have a component that has db access and I have reused it in several contexts. In some of them it uses a standard connection string coming from the config file, while in others I have another component that decides which connection string to use based on some conditions.

    If you go for the second approach, you’ll need to change the code in order to support such a functionality.

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

Sidebar

Related Questions

I didn't see any output in the console or Visual Studio's output panel from:
http://en.wikipedia.org/wiki/Server_Side_Includes For dynamic contents, I don't see any benefit of SSI,is that the case?
As I wanted to benefit from new multicore threading improvements from .Net Framework 4,
Is there any performance benefit to using const or readonly fields compared to regular,
I can't see any drawbacks in making String.indexOf part of the interface CharSequence .
I'm looking at using ASP.Net MVC as a platform for a REST based Service.
I didn't see any similar questions asked on this topic, and I had to
Would I expect to see any performance gain by building my native C++ Client
I am curious to see any alternative(s) to the regular if statements such as
I hardly see any pointer on the following problem related to Hibernate. This pertains

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.