LightInject
LightInject copied to clipboard
GetAllInstances misses some of my instances
Hi,
I've got some problems with the GetAllInstances method which didn't gave me all the desired instances. Here is the context:
- one main project with 3 assemblies (for each of them I've got a CompositionRoot and its declaration thru the Assembly attribute)
- each assembly register an IModuleTag with a dedicated and unique service name
- for each Assembly, I use the RegisterAssembly method
- in the end, I try to gather all my IModuleTag instances
When I use the GetAllInstances method, I just get 1 of my instances but when I ask for them separately (and of course using their names), I can found them (below an extract of my test)
_container.GetInstance<IModuleTag>());
=> Yes found
_container.GetInstance<IModuleTag>("account"));
=> Yes found
_container.GetInstance<IModuleTag>("admin"));
=> Yes found
_container.GetInstance<IModuleTag>("import"));
=> Yes found
_container.GetAllInstances<IModuleTag>().Count());
=> 1 which is "account"
_container.GetAllInstances(typeof(IModuleTag)).Count());$
=> 1 which is "account"
Any idea?
EDIT: I missed to give some details:
- LightInject : 4.0.8
- LightInject.Annotation: 1.0.0.4
Can you produce a simple console application with this code?
I think the issue is related to services being registered after the first call to GetAllInstances.
Would it be possible for you to ensure that all composition roots has been executed before you start to requesting services from the container?
Hi,
Unfortunately, I have to register my services in "at least" 2 steps. I will try to use, the first time, only the "GetInstance" method and then the "GetAllInstances".
I took a look in the container and I found out that the "emitters" and the "availableServices" contain my registered services.
I dont know if it should be consider as a bug or an improvement, but it'll be super cool that have this scenario working.