Skip to content
This repository has been archived by the owner on Jul 3, 2019. It is now read-only.

DependencyProvider and getInstance() #61

Closed
darscan opened this issue Nov 10, 2011 · 2 comments
Closed

DependencyProvider and getInstance() #61

darscan opened this issue Nov 10, 2011 · 2 comments

Comments

@darscan
Copy link
Contributor

darscan commented Nov 10, 2011

What is provided as the targetType to apply() when getInstance() is called manually? I have a situation where I need to use getInstance() rather than an Inject point, but the provider needs the targetType. At the moment it seems to pass the requested type.

@tschneidereit
Copy link
Owner

Yep, it's the requested type. I only saw the option of passing null or
the requested type itself, both not making too much sense, really.

The only way to pass the targetType for getInstance would be to change
that method's signature. Unfortunately, I think that that's pretty
hard to understand. Implementing your own dependency provider really
is something entirely different from using the injector's default API,
don't you think?

On Thu, Nov 10, 2011 at 20:32, Shaun Smith
reply@reply.github.com
wrote:

What is provided as the targetType to apply() when getInstance() is called manually? I have a situation where I need to use getInstance() rather than an Inject point, but the provider needs the targetType. At the moment it seems to pass the requested type.


Reply to this email directly or view it on GitHub:
#61

@darscan
Copy link
Contributor Author

darscan commented Nov 10, 2011

Yeh, it's a tricky one. It cropped up while creating a provider for loggers:

https://github.com/robotlegs/robotlegs-framework/blob/4149bed1f83ef04e09d18e21c4f8ccc1420f6691/src/org/robotlegs/v2/extensions/logging/integration/LoggerProvider.as

There are some places where I need to pull out a fresh logger with getInstance() as the class I'm in doesn't get injected into. The only solutions I can think of are:

Expanding the getInstance signature:

getInstance(type, name="", targetType="")

or adding a new method:

getInstanceFor(type, name="", targetType="")

neither of which are terribly pretty :/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants