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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:36:53+00:00 2026-05-28T06:36:53+00:00

In the code of the project I’m working on I encountered a strange approach.

  • 0

In the code of the project I’m working on I encountered a strange approach.

The UI layer gets dependecies using a sort of Service Locator which is a class with static methods:

public class ServiceManager {

    public static MailService getMailService() {
        ...
    }

    public static UserInfoService getUserInfoService() {
        ...
    }
    ...
}

The dependencies that are “distributed” by this class are injected to it using Spring framework.

What could be the reason for this approach? I can see only downsides. Since the locator methods are static, there is no interface. The absence of interface makes it harder to reason about the purpose of the class. Clients of this class are tightly coupled to it (remember, no interface there), making them impossible to reuse elsewhere.

Wouldn’t it be much better to let Spring inject dependencies in the UI classes directly?

  • 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-28T06:36:54+00:00Added an answer on May 28, 2026 at 6:36 am

    With most UI frameworks, it is often very hard (if not impossible) to use constructor injection in the UI classes. In that case it is common to revert to the Service Locator pattern, but only -I repeat only– in the UI classes.

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

Sidebar

Related Questions

I'm working with PDFs in VB.NET using a DLL I found on code project:
I am recently working with a F90 code project. I am using gfortran (linux
I am using GCC 4.7 and compiling my C++ code-project. The code consists of
I am going through my project code base, which consits of libraries and applications.
I'm using SVN with Google Code Project Hosting for a school project. As the
I came across this article on Code Project that talks about using an abstract
I've seen discussed the MVC project structure using a UI Project and a Code
I'm using Matt Gallagher's Audio Streaming Project . I downloaded the code/project and it
Im using a Custom NestedRepeater Control for ASP.NET which can be found on code
I followed this code project tutorial for using SharpGL with WPF to create a

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.