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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:10:37+00:00 2026-05-23T04:10:37+00:00

I have a small web application that I am building. Primarily to improve my

  • 0

I have a small web application that I am building. Primarily to improve my unit testing ability (and also decouple my code further) I am implementing a service locator pattern to look up concrete implementations of some dependencies. I am mostly happy with the Service Locator singleton class itself, but I’m curious about where to put it and how to load it. The singleton essentially manages a hashmap of interface -> concrete implementations.

I have several projects in my workspace:

1) A presentation layer project which contains the servlet code and presentation layer processing. (uses 2 and 3 below)

2) A data access layer project which contains the code to access the databases etc. (uses 3 below)

3) A common project containing the various data models used by both layers. (no other project references)

Since the service locator is to serve up implementations of classes in both projects 1 and 2 above, I’m wondering where best to put it?

Another question I’m stuck on is how best to load it up with default implementations. One option is to put all the default implementations into the constructor of the singleton service locator class. E.g.:

private ServiceLocator() {
   services.put(ISomeClass.class, new SomeClass());
   ....
}

Another option is to have a separate class whose responsibility is to load the ServiceLocator with default implementations. But then the question is how to get it invoked so that the default implementations are loaded before any other class.

So I guess my two questions are:

1) In which project does the ServiceLocator best fit?

2) What solutions do you recommend for loading up the class with default implementations?

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-23T04:10:38+00:00Added an answer on May 23, 2026 at 4:10 am

    I think Martin Fowlers article on Dependency Injection addresses some of your questions. Personally I am not the biggest fan of the service locator pattern especially in Java where there are many high quality DI frameworks out there (although that it admittedly might be an overkill, but since you have to think about these kinds of architectural decision on implementing the service locator already you might eventually need to switch anyway). To your questions:

    1) I would say in a separate project that has dependencies on 1) and 2)
    2) From the mentioned article:

    Dependency injection and a service
    locator aren’t necessarily mutually
    exclusive concepts. A good example of
    using both together is the Avalon
    framework. Avalon uses a service
    locator, but uses injection to tell
    components where to find the locator.

    So you could also use dependency injection to fill the locator with default implementations.

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

Sidebar

Related Questions

I am building a small web application. I have two divs. One is absolute
I have a small web.py Python application that I would like to serve under
I'm making a small web application in Seaside. I have a login component, and
I am developing a small intranet based web application. I have YSlow installed and
I am building a small web application in c#. I am using the range
I am currently building a small web application for publishing stories using PHP and
I'm building a very small web ERP application with PHP / mySQL / CodeIgniter
I'm building a small web application with ASP.NET MVC 2, using db4o as a
I have a web application that I developed with the Google Web Toolkit (GWT),
I am building a small application in RoR that has a form asking for

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.