Questions tagged [common-service-locator]
33 questions
39
votes
4 answers
When would you use the Common Service Locator?
I've been looking at the Common Service Locator as a way of abstracting my IoC container but I've been noticing that some people are strongly against this type of this.
Do people recommend never using it? Always using it? or sometimes using it?
If…

ajma
- 12,106
- 12
- 71
- 90
14
votes
1 answer
How do I use Common Service Locator in Ninject 2
Changes in Ninject 2 say that Ninject support Common Service Locator, but how do I use it? I don't find any manual or sample.

magol
- 6,135
- 17
- 65
- 120
12
votes
2 answers
How is the intention of IServiceLocator.GetInstance(Type) different from the intention of IServiceProvider.GetService(Type)?
Is there a difference in intentions of the method signatures IServiceProvider.GetService(Type serviceType) and IServiceLocator.GetInstance(Type serviceType)? If so, what is the distinction?
I've always treated them as equivalent but made a choice…

smartcaveman
- 41,281
- 29
- 127
- 212
9
votes
1 answer
Is the Common Service Locator widely used?
I'm working on a new project now, and have given some thought to the IoC setup. I'm aware that you shouldn't be depending on the service location pattern (much, anyway), but that there are just a few places in a well-structured application where it…

Grant Palin
- 4,546
- 3
- 36
- 55
4
votes
1 answer
What's the difference between GetService and GetInstance in CSL
I'm coding against Common Service Locator and I'm having trouble figuring out the semantic differences between GetInstance, GetAllInstances, and GetService (GetAllInstances is pretty obvious, but both GetInstance and GetService seem to return an…

Ana Betts
- 73,868
- 16
- 141
- 209
4
votes
1 answer
What is the meaning of the word ambient in this comment from CommonServiceLocator?
I want to guess that "ambient container" has something to do with the fact that it's a static class, but that's just a guess.
Or is this referring to a standard pattern? (i.e. I really need to read that GoF book cover to cover)
namespace…

Aaron Anodide
- 16,906
- 15
- 62
- 121
3
votes
1 answer
Autofac to Common Service Locator (TypedParameter issue)
How do i modify the following from Autofac to use the Common Service Locator (where _context is of type IComponentContext):
var query = _context.Resolve(TypedParameter.From(this));
The code above is taken from…

nfplee
- 7,643
- 12
- 63
- 124
3
votes
1 answer
Is it a good practise to use CommonServiceLocator to inject dependencies into base class?
Currently when I need to inject dependencies into base class, I use the following code:
public class BaseClass
{
readonly IService _service;
public BaseClass(IService service)
{
_service = service;
}
}
public class A :…
user593358
3
votes
0 answers
Asp.net core: injecting into event handler?
I've got an asp.net core app and this is my set-up:
services.AddSingleton(typeof(ISchedule), typeof(MySchedule));
services.AddLogging();
services.AddScheduler((sender, args) =>
{
// How do I log here?
});
Unfortunately I don't have control over…

Volker
- 1,753
- 2
- 18
- 28
3
votes
1 answer
Ninject how to access kernel to create instances?
I am new to ninject using ninject 2.0. My application is hosted in asp.net mvc.
Now i don't know how to access kernel created in my class library.
I think i should create kernel in global.aspx and load all modules in it. But how can i make it…

mamu
- 12,184
- 19
- 69
- 92
3
votes
2 answers
IoC from start to finish
I'm quite sure that IoC is the way to go for my application. There are a ton of articles and even questions here on SO that discuss the different containers. I've read several blogs today with partial examples. I am personally leaning towards…

Dave
- 14,618
- 13
- 91
- 145
3
votes
2 answers
Dependency injection and service location
As far as i know dependency injection is not the same as service location. but the Unity application block contains the Common Service Locator library (which i think is a service locator). how that library should be used and when should it be used,…

Ibrahim Najjar
- 19,178
- 4
- 69
- 95
2
votes
0 answers
How to access Autofac built container in Generic Host
I know in ASP.NET Core you can use GetAutofacRoot:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
// If, for some reason, you need a reference to the built container, you
// can use the convenience extension…

Ismael
- 361
- 3
- 9
2
votes
2 answers
Does the Common Service Locator support Mono .NET?
Does the Common Service Locator, used for "providing an abstraction over IoC containers and service locators", support Mono .NET?

Simon
- 1,499
- 3
- 17
- 23
2
votes
3 answers
A package is listed in Updates in NuGet manager and cannot be removed
This is a problem I've had for quite a long time, but because we're closing this project at work, I thought I might finally sort it out. When I check updates for our NuGet packages, the list always shows this (+ any actual available updates):
When…

Filip Vondrášek
- 1,208
- 1
- 13
- 26