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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:24:26+00:00 2026-05-14T02:24:26+00:00

Just trying to still get my head around IOC principles. Q1: Static Methods –

  • 0

Just trying to still get my head around IOC principles.

Q1: Static Methods – Should util classes with static helper methods be wired up with IOC?

For example if I have a HttpUtils class with a number of static methods, should I be trying to pass it to other business logic classes via IOC?

Follow on questions for this might be:

Q2: Singletons – What about things like logging where you may typically get access to it via a Logger.getInstance() type call. Would you normally leave this as is, and NOT use IOC for injecting the logger into business classes that need it?

Q3: Static Classes – I haven’t really used this concept, but are there any guidelines for how you’d typically handle this if you were moving to an IOC based approach.

Thanks in advance.

  • 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-14T02:24:26+00:00Added an answer on May 14, 2026 at 2:24 am

    The funny thing about IoC is that objects written in the style are generally decoupled from those details.

    Let’s use the utility class as an example:

    public class HttpUtils
    {
        public static void DoStuff(int someValue)
        {
            // ...
        }
    }
    

    In a non-IoC-focused application, you might use that method directly:

    public class Foo
    {
        public int Value { get; set; }
    
        public void DoStuff()
        {
            HttpUtils.DoStuff(Value);
        }
    }
    

    However, that couples the definition of DoStuff directly to its implementation. IoC strives to divorce those kinds of details, so instead we define the operation on its own:

    public interface IDoesStuff
    {
        void DoStuff(int someValue);
    }
    

    Then, we leave room in Foo for the implementation to change:

    public class Foo
    {
        private readonly IDoesStuff _doesStuff;
    
        public Foo(IDoesStuff doesStuff)
        {
            _doesStuff = doesStuff;
        }
    
        public int Value { get; set; }
    
        public void DoStuff()
        {
            _doesStuff.DoStuff(Value);
        }
    }
    

    This decouples Foo from HttpUtils. The implementer of the concept of DoStuff is now a configuration detail, and not an inherent dependency (as it is with the static method).

    Notice that Foo has no idea if its IDoesStuff is a singleton or not. That lifetime is also a configuration detail, and not an inherent detail of Foo.

    To sum up, IoC and static are generally at odds, since IoC promotes change and static, by definition, prevents it. Declare your dependencies in your constructors, and you’ll find you almost never have you use static functionality.

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

Sidebar

Related Questions

still cannot figure out what I am doing wrong. Just trying to get a
I'm a total Javascript newb, and I'm trying to wrap my head around OLN.
I am still learning jQuery and have come up against something I just can't
I'm getting this error (see title) while trying to parse an XML file in
I am trying to simply NSLog the output of the new iPhone 4 Gyroscope.
I have a view that I have been trying to map in either entity
Using Visual Studio, after attaching to a Process and pressing Pause (Break-All), you switch
I would guess it's the simplest thing but it's really confusing me. I'm sure
I'm getting an Object reference not set to an instance of an object error
I have the following HttpModule that I wanted to unit test. Problem is 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.