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

The Archive Base Latest Questions

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

I currently have a class in which I only have static members and constants,

  • 0

I currently have a class in which I only have static members and constants, however I’d like to replace it with a singleton wrapped in an interface.

But how can I do this, bearing in mind that every singleton implementation I’ve seen has a static Instance method, thus breaking interface rules?

  • 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-18T23:28:07+00:00Added an answer on May 18, 2026 at 11:28 pm

    A solution to consider (rather than hand-rolling your own) would be to leverage an IoC container e.g. Unity.

    IoC containers commonly support registering an instance against an interface. This provides your singleton behaviour as clients resolving against the interface will receive the single instance.

      //Register instance at some starting point in your application
      container.RegisterInstance<IActiveSessionService>(new ActiveSessionService());
    
      //This single instance can then be resolved by clients directly, but usually it
      //will be automatically resolved as a dependency when you resolve other types. 
      IActiveSessionService session = container.Resolve<IActiveSessionService>();
    

    You will also get the added advantage that you can vary the implementation of the singleton easily as it is registered against an interface. This can be useful for production, but perhaps more so for testing. True singletons can be quite painful in test environments.

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

Sidebar

Related Questions

I currently have a custom session handler class which simply builds on php's session
I have a class named Page with a private property currently called _pageData which
I currently have my PHP class variables set up like this: class someThing {
I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
I would like to add an operator to a class. I currently have a
I'm currently writing a class that implements the SeekableIterator interface and have run into
I currently have a class and I'm trying to create an easy GUI to
All, I currently have my solution comprising of 2 Class librarys and a Web
The current class library I am working on will have a base class (Field)
I currently have an MS Access application that connects to a PostgreSQL database via

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.