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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:33:25+00:00 2026-05-29T15:33:25+00:00

I have built a little static object for saving generic types to Isolated Storage

  • 0

I have built a little static object for saving generic types to Isolated Storage on WP7. This works grand for older projects but some of the new projects use DI to manage configuration. I am a fan of DI as it means I can change the configuration in one place and have it filter down to all dependencies.

My thought was to create a namespace called Injection and wrap this object in an instance with an interface so I could inject it about. It would also enable me to swap out the storage handler for ones that require a more specific implementation.

Is this common practice or is this an anti pattern?

As a note, I want to keep the static option as not everyone needs or can use DI. I am simply trying to enable both with the least amount of duplication.

  • 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-29T15:33:25+00:00Added an answer on May 29, 2026 at 3:33 pm

    You see this all the time. Mostly it’s to work around legacy code which is already static or sealed or doesn’t implement any interfaces. While a base class instead of an interface, HttpContextBase is the most prominent example I can think of.

    Since you want to keep the static option, that’s basically the situation you are currently in, so go ahead and do it. I wouldn’t create an Injection namespace, though, as that name says more about the mechanics than the role the object plays.

    You don’t write exactly how the class is static, but I’m assuming that we are talking about a static class with static methods.

    A slightly more elegant solution (if you can change the class a bit) is to turn the static class into a Singleton. Then it could be static and implement the interface at the same time:

    public class Foo : IFoo
    {
        private readonly static Foo instance = new Foo();
    
        private Foo() { }
    
        public static Foo Instance
        {
            get { return Foo.instance; }
        }
    
        // IFoo member:
        public void InterfaceFoo()
        {
            Foo.LegacyFoo();
        }
    
        public static void LegacyFoo()
        {
            // Implementation goes here...
        }
    }
    

    I think the only refactoring required to arrive at such a solution is to make the class itself concrete and make it implement the interface as a Singleton.

    Old clients could still access its methods by invoking Foo.LegacyFoo();

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

Sidebar

Related Questions

We have a little in-house LMS with courses built in Flash. Scores are updated
In our infrastructure, we have lots of little Java projects built by Maven2. Each
I have this nice little MSBuild-based daily build setup that I use on my
i have little experience with Liferay, builded a couple of sites with static content
I have a binary tree based mathematical expression parser I built, which works great
I have built a little repeater HtmlHelper for asp.net MVC and I would like
I have built my first few scripts with a nice little GUI on them,
I have built a little daemon in Java and I would like to run
Good day. I have little usage of Flash CS4, however i have to build
I have a site I'm trying to build and I've hit one little snag

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.