Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [service-locator]

The service locator is a design pattern that aims at decoupling the use of an abstract services from concrete implementations of these services. This pattern encapsulates the determination of the concrete implementation to use and implements the principle of dependency inversion.

1
vote
1answer
145 views

How to design a reassignable global instance that can be referenced by many other classes

I have a DeviceManager class which can handle different physical devices, and to say there are Classes A,B,C, which require a DeviceManager instance as dependency. They should always use the same ...
0
votes
1answer
63 views

What pattern should I use to implement a Message Routing mechanism?

I'm hoping someone can give some guidance on an issue I'm having. I have: A WebSocket service, where I have a single method on the server that handles all traffic. Lots of different kinds of ...
4
votes
3answers
294 views

Decoupled design using static interfaces

Now first I want to mention that I am not quite sure what is the term describing the issue at hand but I hope that I can illustrate it with some code. Problem: A shared class library defines an ...
1
vote
1answer
53 views

Does a service-locator lead to more straightforward code in this situation?

Assume I have a class like this: public interface IService { // Gets some data, possibly from a website / database List<string> GetStrings(); } public class ItemViewModel : ...
2
votes
2answers
2k views

Unity injection with too many constructor parameters

The question is about choosing the appropriate design for the scenario described below. This is a repost from https://stackoverflow.com/questions/51940180/unity-injection-with-too-many-constructor-...
2
votes
2answers
572 views

Dependency Injection and DI Container

I have implemented clean architecture for my app, and I have a few questions. Typically, pure DI is argued for over a Service Locator pattern, because it is very explicit and more testable. However, ...
1
vote
0answers
64 views

What is the appropriate pattern for an extendable application framework?

I have created a basic, domain-specific application framework for a web-based GUI. The framework provides Undo/Redo of 'Operations', persistence, and other more domain-specific functionality. I am now ...
3
votes
3answers
335 views

IOC container & accessing Implementation from the container

Background As mentioned in this article, Inversion of Control can be achieved through various mechanisms such as: Strategy design pattern, Service Locator pattern(SLP), Factory pattern, and ...
4
votes
2answers
5k views

How to separate the ViewModel from the Model, yet associate them with each other based on the Model?

In a wpf application, a Model object is created either from scratch or deserialized from some .xml file. To create a connection to the ViewModel, the following method (on the Model!) is used by the ...
1
vote
1answer
2k views

Service locator vs Dependency Injection?

I have a class which acts as a Adaptor between an HTTP request and our Application's custom domain request. So every Http request element: URI, headers, content are mapped to our customized domain ...
1
vote
4answers
855 views

Image processing - Service locator pattern & Container of dependencies

As per wiki, A dependency is an object that can be used (as a service). here is the OOP paradigm using C syntax that address 4 roles, shown below. 1) interface (handlers.h) typedef struct { ...
5
votes
3answers
888 views

DependencyInjection - Constructor over-injection smell vs service locator - where is the proper approach?

I am trying to improve my MVC projects and I read a few articles about DI, IoC containers, Constructor Injection and Service locators. I wanted to go with Ninject to help with the dependencies, but ...
13
votes
3answers
369 views

Multitudes constructing one implementation. DI hopeless? Use service locator?

Say we have 1001 clients that construct their dependencies directly rather than accept injections. Refactoring the 1001 is not an option according to our boss. We're actually not even allowed access ...
1
vote
0answers
82 views

How can I load service dependencies into model classes?

My model objects are generated by the library using hard-wired new operators, which makes dependencies injection using the constructor impossible. However, they also have methods, which are called by ...
6
votes
1answer
224 views

How do I remove smell from a pluggable DAL

I am working with an application that is composed of several different, disconnected, components and each piece has a dependency on up to three different Data Stores (SQL Server, Doc Storage, BLOB ...
7
votes
2answers
340 views

In an enterprise architecture, where is Service Locator most appropriately used, and why?

I'm trying to implement the Service Locator pattern. In the below diagram is my references between projects (.net projects), each box represents a project. The arrows indicate the dependencies. I ...
1
vote
1answer
3k views

Using ninject in a class library

Looking for some help getting my head around ninject and DI. Using the simple examples I've found online everything works nicely but trying to do something more complex is causing headaches. I have ...
5
votes
3answers
1k views

Ambient dependency injection through static service locator

After some googling I found some debates about whether constructor injection or property/field injection is better, but there is yet another alternative that strikes me as more beneficial. In most ...
8
votes
2answers
2k views

Service-locator anti-pattern alternative

I'm using Unity as IoC with C#, but I guess the question really isn't really limited to Unity and C#, but IoC in general. I try to follow the SOLID-principle, which means that I got very few ...
4
votes
2answers
7k views

Only use a dependency injection container at the root of an application?

normally, I'll use a dependency injection container (unity) in c# like this example: class SomeClass { private readonly ILogger _logger; public SomeClass() { _logger = ...
2
votes
1answer
110 views

How far do I, or can I take TDD tests with Service Objects?

In writing PHPSPEC tests for a Zend Framework 2 application, I'm left wondering how far to 'dig'. Consider this very simple case: A DomainService (Domain in the URL sense of the word) should be ...
1
vote
4answers
192 views

Is it ok to use service locator for ubiquitously used dependencies? [closed]

We strictly adhere to inversion of control in our codebase, but that creates hellish constructors (yes, I know that means our classes aren't cohesive enough, this is a work in progress). The thing is, ...
0
votes
2answers
1k views

How to avoid using service location when using dependency injection? [closed]

I am trying to use dependency injection in a WPF application, and I really can't figure how to avoid using service location, which is considered to be an anti-pattern in many articles. I am using the ...
5
votes
1answer
2k views

Pattern for communicating between nested usercontrols and parent form (C# / Winforms)

I'm trying to decide the best way to handle communication between a UserControl that is nested within another UserControl and the parent Form itself. I have a Form, inside the form there's a ...
2
votes
2answers
399 views

Dependency injection of ViewModel with unmanaged parameter

I have a PersonEditViewModel which needs two other objects, the personId and the PersonRepository. PersonRepository is obtained from a service locator: private final int personId; public ...
2
votes
1answer
1k views

How to deal with dependency when you have separate projects?

I know there is all this talk about having only one composition root that set all your dependencies and that you should always prefer constructor injection to other types, but sometimes it just doesn'...
2
votes
1answer
766 views

Where to keep persistent services in MVVM architecture?

In an MVVM application I need to use some services that are persistent, e.g. network services like P2P and WCF where the main "engine" or server endpoint must remain up and running during the lifetime ...
0
votes
1answer
887 views

Is this a good service locator, and is this service locator pattern(?) OK?

I'm working in Zend framework 1 and was using Zend_Registry to store objects so that I could replace them in my controllers while unit testing: $auth = Zend_Registry::get('Auth'); // set in Bootstrap....
1
vote
1answer
107 views

Lookup pattern as a way of passing global references

I am looking at some legacy code in java that uses the Service Locator pattern as a way of passing global references as opposed to passing them over and over again through method arguments and I am ...
4
votes
2answers
1k views

IoC as service locator

I have been wondering for quite some time on some issues while using dependency injection: In a layered application, I normally inject repositories into the application service using constructor ...
0
votes
1answer
937 views

How can I use guice to replace code dependent on service locator implementation?

Consider I have a service called FileSystem, and that this FileSystem is used by various classes throughout the application. Typically, the service is acquired via some static class method ...
4
votes
2answers
147 views

How to extend Constructor Injection?

Suppose I have MyClass with a very simple dependency. It uses constructor injection. public class MyClass : IMyClass { private IA A; public MyClass(IA a) { A = a; } } This ...
5
votes
2answers
913 views

How to decouple simple factory and default implementation?

I have a simple factory class (FileResources) with static factory methods providing a default implementation (DefaultFileResource). public final class FileResources { private FileResources() {} ...
0
votes
4answers
839 views

API design with references to root object

[Normally I post on StackOverflow but as this is more a design/theory question rather than a code question I'll give it a shot here] Most of my applications currently use a core object model that I ...
1
vote
1answer
546 views

How should dependencies be managed across a modular application?

Let's say that we have a structure like this: Application -- Modules --Module1 -- Controller -- PublicHelper --Module2 -- Controller ...
3
votes
3answers
1k views

What is a Service Locator?

I've heard the term pop all around. I've read various articles regarding the subject and heard two main definitions to the term "Service Location": A glorified Registry - Bad practice, global ...
0
votes
0answers
169 views

Refactoring expansive message architecture

I am currently working with a system that acts like a message bus. A message comes in to the service (WCF Windows Service hosted). The system then uses a service locator pattern to look up which ...
3
votes
2answers
752 views

Desktop application, dependency injection

I am thinking of applying a real dependency injection library to my toy C#/GTK# desktop application. I chose NInject, but I think this is irrelevant to my question. There is a database object, a main ...
4
votes
2answers
5k views

IoC containers and service locator pattern

I am trying to get an understanding of Inversion of Control and the dos and donts of this. Of all the articles I read, there is one by Mark Seemann (which is widely linked to in SO) which strongly ...
7
votes
3answers
5k views

Inject dependency as method parameter instead of constructor parameter

I'm using an ORM which doesn't allow me to inject dependencies in the constructor. Let's say I'm using DDD for the business logic, and the MVC pattern for the UI. Now one of my domain objects needs ...
3
votes
1answer
2k views

Better to inject IoC container or use a Service Locator pattern? [duplicate]

I have an IoC container (If you want a specific one to look at, it's very similar to Unity) and I'm working on how I want to integrate it into my application. My overall goal for this exercise is to ...