I wrote a great application using DI. The application consists of a bootstrap during initialization, where most of the dependencies are introduced. All is well.
However, there are some services * that I cannot just deploy everywhere. One good example is the journal service. This is a log, so each individual class in a solution may want to use it for debugging or tracing purposes. Not every class is created during initialization, some of them are provided by a third party (the application is to some extent the basis). Right now, my decision is to use singles; I even created some wrapper classes for singleton, so I can inject it where possible.
I was wondering if the best approach would be to use ServiceLocator in these places. . This completes the removal of the hard link that the singleton calls. Of course, the classes will be bound to the locator, but I could provide them with any implementation.
* In DDD terminology.
PS: I use .NET here, but I will not mark it; I believe this question applies to any language that accepts DI.
source
share