I have a @Injectable
service defined in bootstrap. I want to get the instance of the service without using constructor injection. I tried using ReflectiveInjector.resolveAndCreate
but that seem to create a new instance.
The reason I'm trying to do is I have a base component derived by many components. Now I need to access a service but I don't want to add it to the ctor because I don't want to inject the service on all of the derivative components.
TLDR: I need a ServiceLocator.GetInstance<T>()
UPDATE: Updated code for RC5+: Storing injector instance for use in components
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…