java - Guice: When to kick off injection/bootstrapping in a headless JAR? -


so i'm writing bunch of components (that packaged jars), , using guice di. these components reusable, "commons"-type jars used other downstream projects.

my understanding guice implement concrete module , use bind objects and, in effect, configure of di. understanding should have single "bootstrapping" phase guice injector created, , dependencies module configured fetched injector injector.getinstance(someclass.class).

that work great in standalone application, had entry point, invoke init()-style method bootstrap guice with, in headless jar has no entry point, i'm struggling trying determine when/where/how bootstrap guice.

these jars living on classpath and, @ point in time, external entity invoke , class , method inside of them. thought using "lazy initialization" set up, method checks see if dependencies have been configured yet, and, if so, kicks off bootstrap method.

but that's terrible solution! partly, because require every class have own module (which ridiculous), , pollute entire codebase di-related code.

i'm missing guice fundamentals here, otherwise don't see how guice used in other app execution start finished known , controlled. code samples huge plus! in advance.

if other code wants configure classes without using guice, should able to. however, should provide guice module binds in reasonable way other code (perhaps other modules) can install module, , inject dependencies own classes.

of course, don't need expose module @ - can leave others perform binding. however, may wish provide module avoid exposing implementation details - can expose public interface , public module, keep implementation package-private. module can bind interface implementation without caller knowing it.

you may want investigate private modules, can bind dependencies your code needs, without exposing them more widely.

something, somewhere going have create injector - if code "library" code, certainly shouldn't you. shouldn't performing injection - should making code amenable injection.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -