java - Why field is injected into existing instance? -
i've found piece of code this
bind(my.class).to(new myprovider()) class myprovider implements provider<my> { @inject injector injector = null; get() { return new my(injector.getinstance(another.class)); } }
i've found guice injects injector later when injector being created though provider created new
.
questions are:
- is specified guice or accidental implementation detail?
- is specified in jsr-330?
- can rely on it?
- how other di frameworks behave in such case?
- if isn't specified anywhere, how 1 rewrite this? note i've omitted details, there several named bindings of same interface , each provider instance gets name parameter , gets named service injector.
Comments
Post a Comment