@@ -92,6 +92,8 @@ public class Jooby implements Router, Registry {
9292
9393 private EnvironmentOptions environmentOptions ;
9494
95+ private boolean lateInit ;
96+
9597 /**
9698 * Creates a new Jooby instance.
9799 */
@@ -310,7 +312,7 @@ public Jooby renderer(@Nonnull MediaType contentType, @Nonnull Renderer renderer
310312 * @return This application.
311313 */
312314 @ Nonnull public Jooby install (@ Nonnull Extension extension ) {
313- if (extension .lateinit ()) {
315+ if (lateInit || extension .lateinit ()) {
314316 onStarting (() -> extension .install (this ));
315317 } else {
316318 try {
@@ -477,13 +479,6 @@ public Jooby errorCode(@Nonnull Class<? extends Throwable> type,
477479 return this .router .getServices ();
478480 }
479481
480- private Registry checkRegistry () {
481- if (registry == null ) {
482- throw new IllegalStateException ("No registry available" );
483- }
484- return registry ;
485- }
486-
487482 /**
488483 * Get base application package. This is the package from where application was initialized
489484 * or the package of a Jooby application sub-class.
@@ -627,6 +622,21 @@ private Registry checkRegistry() {
627622 return this ;
628623 }
629624
625+ /**
626+ * Force all module to be initialized lazily at application startup time (not at
627+ * creation/instantiation time).
628+ *
629+ * This option is present mostly for unit-test where you need to instantiated a Jooby instance
630+ * without running extensions.
631+ *
632+ * @param lateInit True for late init.
633+ * @return This application.
634+ */
635+ public Jooby setLateInit (boolean lateInit ) {
636+ this .lateInit = lateInit ;
637+ return this ;
638+ }
639+
630640 @ Override public String toString () {
631641 return router .toString ();
632642 }
0 commit comments