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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:01+00:00 2026-05-25T14:23:01+00:00

read many posts about the difference between the 3 idioms. But got more confused,

  • 0

read many posts about the difference between the 3 idioms. But got more confused, then I ran into this article:
http://martinfowler.com/articles/injection.html

just want to see if I got this right. please correct me if I’m wrong.
Please notify me of correction and additions:

IoC- is the concept of decoupling an application from the implementation of a service it uses. The application contain a ref to Iservice and is not incharge of instanciating the concrete service.

There are at least two way to achive so:

  1. DI – The concrete service is injected as a ctor param/throw a setter/throw interface injection (what does the latter mean?)

  2. ServiceLocator – is a component that knows all the concrete services the application may need. The application explicitly asks for the concrete service from the Locator.

*IoC container is actualy a controls’ factory (“provider”).

I got a bit confused by the “when to prefer (1) or (2)” part in the article. could someone please tell from his own experience in a layman words ?

“Service Locator has a slight edge due to its more straightforward behavior. However if you are building classes to be used in multiple applications then Dependency Injection is a better choice.”–> How is locator more straightforward ? because it uses method invocation explicitly ? What is it better to use DI when there are multiple applications?

  • 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-25T14:23:02+00:00Added an answer on May 25, 2026 at 2:23 pm

    IoC is the concept of decoupling an application from the implementation of a service it uses.

    It is true that IoC goes hand in hand with decoupling interfaces from implementations, but I see it as a more general principle. This SO answer gives a very good explanation of the concept.

    There are at least two way to achive so:
    1) DI
    2) ServiceLocator

    I wouldn’t say that the Service Locator pattern is an example of Inversion of Control. Quite the opposite – when you are using the Service Locator, you are acquiring the required dependencies in active way, nobody else does it for you (contrary to the DI, where the container handles the dependencies for you, you just have to give it a possibility of doing so – a setter, a constructor parameter or by implementing method of injection interface).

    How is locator more straightforward ? because it uses method invocation explicitly?

    I think that Martin Fowler is referring to the general idea of IoC that may make the code harder to understand if you’ve never seen the IoC/DI concept used before. On the other hand, the code using Service Locator to acquire some dependencies may be easier to grasp on first encounter.

    What is it better to use DI when there are multiple applications?

    When you are creating a component that is supposed to be reusable, the advantage of DI is that it doesn’t make your component dependent on anything else than the original dependency (in MF’s example, the MovieLister depends only on the MovieFinder interface when using DI).
    Also, it is quite easy for others to use your component – the just have to pass the dependencies using the means of DI you provided.

    When using the Service Locator, you also add dependency on the interface of the Service Locator itself. With segregated interface for the Locator, that may not be a problem. But it may also be harder for users of your component to satisfy the dependencies of your component, as MF writes:

    The difference comes if the lister is a component that I’m providing to an application that other people are writing. In this case I don’t know much about the APIs of the service locators that my customers are going to use. Each customer might have their own incompatible service locators.

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

Sidebar

Related Questions

I've read many posts about this issue but I never got this to work.
I have read many posts about this now but I do not still understand
I've read through many of the questions on SO about this, but many answers
I've read many posts about this, the last being a statement saying the behaviour
Ok, I have read a lot of posts and resources about this but I
I've read this question: What's the difference between identifying and non-identifying relationships? But I'm
Alright...I've given the site a fair search and have read over many posts about
I already read many article about this issue in here, SO. I just want
I have read many posts about setting up unit testing in Zend Framework and
I have read many posts and blogs about rewriting and I know there is

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.