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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:21:19+00:00 2026-05-25T02:21:19+00:00

In my asp.net application, I have the below static class to handle query strings

  • 0

In my asp.net application, I have the below static class to handle query strings in my app to which some classes have dependency:

public static class QueryStringUtil
{
    public static int? GetStoreId()
    {
        return GetId(QueryStrings.StoreId);
    }

    public static string GetItemCode()
    {
        return Get(QueryStrings.ItemCode);
    }       

    private static string Get(string queryStringName)
    {
        return HttpContext.Current.Request.QueryString[queryStringName];
    }

    private static int? GetId(string queryStringName)
    {
        var queryString = Get(queryStringName);
        int queryStringParsed;
        return int.TryParse(queryString, out queryStringParsed) ? (int?)queryStringParsed : null;
    }
}

What would be the best way to make this class testable?

One way that I know would be to refactor this and create a singleton instance class instead with its interface and enabling the dependent classes to accept an interface of my singleton class. Not sure it would be my best option.

Another option would be to make my class a normal class with interface and then creating a singleton ServiceLocator class responsible to hold instances to all classes that should behave like a singleton, such as my QueryStringUtil, then allowing my dependent class to accept interface to my IQueryStringUtil.

Third option I can think of is not using my Custom Service Locator class instead using an IoC container, such as Microsoft Unity, then holding a singleton instance in the IoC container config file and injecting that to my dependent classes.

Please advise your best option and why.

Many 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-25T02:21:20+00:00Added an answer on May 25, 2026 at 2:21 am

    I really like the last option with the IoC container. This is its power – it is responsible for the lifecycle and dependencies of your objects.

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

Sidebar

Related Questions

I have an asp.net application with a static page method. I'm using the below
I have a Generic HTTP Handler (*.ashx) in my ASP.Net application which performs some
I have a wierd problem with threading in an ASP.NET application. For some reason,
I have ASP.NET application which allows users to download a file when he/she enters
I have a web application which was using Asp.net MVC2 . I Upgraded it
I have a .NET 3.5 web application for which I have implemented a class
I have created a class in my asp.net MVC 3 application's Model folder and
In my ASP.Net application I have a requirement that when a user clicks on
In my ASP.NET application I have a web.config file. In the web.config file I
In my ASP.NET application I have separate projects for the Data, Business and UI

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.