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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:33:04+00:00 2026-05-13T16:33:04+00:00

In order to decouple code you can have service locater’s but is this not

  • 0

In order to decouple code you can have service locater’s but is this not the same as global variables/state?.

I know these often run off interfaces, so you pass in an interface and get a concrete class back but still my question stands.

For example:

class Something {

    void DoSomething() {
        IMyType myType = ServiceLocator.GetSerivceTypeOf(IMyType);
    }
}

Here the class requires MyType which is created somewhere else, but rather than passing MyType down through the chains (via constructors etc…) it is acquired in this manner.

I asked this question early in my professional career as a developer – prior to then I’d not come across this pattern. Anthony has nailed my opinion (and therefore is the selected answer now) on service locator’s – in fact I see them as anti-patterns like others. The links provided are a good starting point – but to somewhat answer my own question after all this time, they act as global state and should be avoided. Prefer standard dependency injection 😉

  • 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-13T16:33:05+00:00Added an answer on May 13, 2026 at 4:33 pm

    Yes they are global variables. Sophisticated ones, but they still have the same basic drawbacks. For that reason, dependency injection is preferable.

    For more detailed discussion of the alternative of constructor injection, see also the question What’s the difference between the Dependency Injection and Service Locator patterns?

    And other web pages Singletons are Pathological Liars and Dependency Injection pattern

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

Sidebar

Related Questions

ORDER BY is not working properly for numbers,but it's working well if I give
Question: Should I decouple the SESSION variables, i.e. move them outside of the class...this
My idea is to use camel to decouple modules. In order to support scalability
Order by descending is not working on LINQ to Entity In the following Query
Order deny,allow deny from all allow from xx.xx.x.xx RewriteRule . - [F] I have
in order to recover data from server I use XMLHttpRequest and my code is
In order to achieve spriting by compass according to the documentation I wrote this:
in order to avoid copy/paste, i can use a unique view for different actions,
I have a big mess of code. Admittedly, I wrote it myself - a
In this stackoverflow question I learned that Prism/Unity is not as decoupled as 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.