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

  • Home
  • SEARCH
  • 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 4248970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:20:00+00:00 2026-05-21T04:20:00+00:00

If I have an object which works as a repository with Save(), GetProduct(prod id)

  • 0

If I have an object which works as a repository with Save(), GetProduct(prod id) etc, is it a good idea for this to be a singleton in an asp.net applications.

My thought is that because I have many accesses to the database, this would improve performance because it doesn’t waist time recreating the repository object each time.
I haven’t seen anything like this in any samples, so why is this wrong?
Thanks

  • 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-21T04:20:01+00:00Added an answer on May 21, 2026 at 4:20 am

    Unfortunately it really depends on how you access your Database, and how your repository class is really abstracting database connections, and transactions.

    If you’re just talking about the expenses of creating an in memory object for every http request then it’s not a big deal. It’s really not worth consideration.

    If you’re talking about low level database stuff, then again, it depends.

    Particularly with ORMs like Linq to SQL or NHibernate, how you manage their sessions is quite important. Usually though you wouldn’t want a “session’s” or “datacontext’s” scope to go beyond the http request, so no, a singleton wouldn’t be a good idea IF the singleton is holding the DB Session as a singleton itself.

    Consider using an IoC Container also, like Castle Windsor. Then to change a particular classe’s “lifestyle” (singleton, transient, per web request, etc.) is a simple configuration change, and makes your application a bit more flexible.

    Also, talking to the DB itself is more expensive that creating new objects in memory, so if you’re really after performance consider clever caching.

    Lastly, when considering Singletons, think about it from a conceptual point of view instead of performance. Does it make sense that this object be Singleton?

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

Sidebar

Related Questions

I have an object which contains models for my ASP.NET MVC web app. The
I have a wizard in my asp.net MVC application which is built upon this
I have a booking app, which accepts a single booking object, and works ok.
I have this object which is an instance of a superclass. I want to
Telerik ASP.NET MVC Q2 2011 I have a grid which is Ajax bound: @(Html.Telerik().Grid<IUser>()
I am using pixel colour picking to work out which OpenGL object I have
I have object A which contains multiple instances of object B, which in turn
I have an object which has several properties that are set when the object
I have an object which needs to destroy itself. Can it be done? Is
I Have a object which the following field : boost::unordered_map<std::string, std::shared_ptr<Foo> > m_liste_; I

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.