8282import java .util .concurrent .TimeUnit ;
8383import java .util .concurrent .atomic .AtomicBoolean ;
8484import java .util .concurrent .atomic .AtomicReference ;
85+ import java .util .function .BiFunction ;
8586import java .util .function .Consumer ;
8687import java .util .function .Function ;
8788import java .util .function .Predicate ;
@@ -696,6 +697,11 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
696697
697698 private boolean throwBootstrapException ;
698699
700+ /**
701+ * creates the injector
702+ */
703+ private transient BiFunction <Stage , com .google .inject .Module , Injector > injectorFactory = Guice ::createInjector ;
704+
699705 /**
700706 * Creates a new {@link Jooby} application.
701707 */
@@ -2016,6 +2022,17 @@ public Jooby map(final Mapper<?> mapper) {
20162022 return this ;
20172023 }
20182024
2025+ /**
2026+ * Use the injection provider to create the Guice injector
2027+ *
2028+ * @param injectorFactory the injection provider
2029+ * @return this instance.
2030+ */
2031+ public Jooby injector (final BiFunction <Stage , com .google .inject .Module , Injector > injectorFactory ) {
2032+ this .injectorFactory = injectorFactory ;
2033+ return this ;
2034+ }
2035+
20192036 /**
20202037 * Bind the provided abstract type to the given implementation:
20212038 *
@@ -2556,8 +2573,7 @@ private Injector bootstrap(final Config args,
25562573 xss (finalEnv );
25572574
25582575 /** dependency injection */
2559- @ SuppressWarnings ("unchecked" )
2560- Injector injector = Guice .createInjector (stage , binder -> {
2576+ com .google .inject .Module joobyModule = binder -> {
25612577
25622578 /** type converters */
25632579 new TypeConverters ().configure (binder );
@@ -2592,8 +2608,8 @@ private Injector bootstrap(final Config args,
25922608 binder .bind (SSLContext .class ).toProvider (SslContextProvider .class );
25932609
25942610 /** routes */
2595- Multibinder <Route . Definition > definitions = Multibinder
2596- .newSetBinder (binder , Route . Definition .class );
2611+ Multibinder <Definition > definitions = Multibinder
2612+ .newSetBinder (binder , Definition .class );
25972613
25982614 /** web sockets */
25992615 Multibinder <WebSocket .Definition > sockets = Multibinder
@@ -2689,10 +2705,10 @@ private Injector bootstrap(final Config args,
26892705 } else {
26902706 binder .bind (SessionManager .class ).to (ServerSessionManager .class ).asEagerSingleton ();
26912707 if (sstore instanceof Class ) {
2692- binder .bind (Session . Store .class ).to ((Class <? extends Store >) sstore )
2708+ binder .bind (Store .class ).to ((Class <? extends Store >) sstore )
26932709 .asEagerSingleton ();
26942710 } else {
2695- binder .bind (Session . Store .class ).toInstance ((Store ) sstore );
2711+ binder .bind (Store .class ).toInstance ((Store ) sstore );
26962712 }
26972713 }
26982714
@@ -2712,7 +2728,9 @@ private Injector bootstrap(final Config args,
27122728
27132729 /** executors. */
27142730 executors .forEach (it -> it .accept (binder ));
2715- });
2731+ };
2732+ @ SuppressWarnings ("unchecked" )
2733+ Injector injector = injectorFactory .apply (stage , joobyModule );
27162734
27172735 onStart .addAll (0 , finalEnv .startTasks ());
27182736 onStarted .addAll (0 , finalEnv .startedTasks ());
0 commit comments