@@ -246,6 +246,15 @@ private void configureTrustProxy(boolean trustProxy) {
246246 }
247247 }
248248
249+ private void configureContextAsService (boolean contextAsService ) {
250+ if (contextAsService ) {
251+ addPostDispatchInitializer (ContextAsServiceInitializer .INSTANCE );
252+ getServices ().put (Context .class , ContextAsServiceInitializer .INSTANCE );
253+ } else {
254+ removePostDispatchInitializer (ContextAsServiceInitializer .INSTANCE );
255+ }
256+ }
257+
249258 @ NonNull @ Override
250259 public Route .Set domain (@ NonNull String domain , @ NonNull Runnable body ) {
251260 return mount (domainPredicate (domain ), body );
@@ -534,10 +543,13 @@ private void pureAscii(String pattern, Consumer<String> consumer) {
534543 }
535544 }
536545
537- @ NonNull public Router start (@ NonNull Jooby app , @ NonNull Server server ) {
538- started = true ;
546+ public void initialize () {
539547 configureTrustProxy (routerOptions .isTrustProxy ());
540548 configureContextAsService (routerOptions .isContextAsService ());
549+ }
550+
551+ @ NonNull public Router start (@ NonNull Jooby app , @ NonNull Server server ) {
552+ started = true ;
541553 var globalErrHandler = defineGlobalErrorHandler (app );
542554 if (err == null ) {
543555 err = globalErrHandler ;
@@ -610,13 +622,6 @@ private void pureAscii(String pattern, Consumer<String> consumer) {
610622 return this ;
611623 }
612624
613- private void configureContextAsService (boolean contextAsService ) {
614- if (contextAsService ) {
615- addPostDispatchInitializer (ContextAsServiceInitializer .INSTANCE );
616- getServices ().put (Context .class , ContextAsServiceInitializer .INSTANCE );
617- }
618- }
619-
620625 /**
621626 * Define the global error handler. If ProblemDetails is enabled the {@link ProblemDetailsHandler}
622627 * instantiated from configuration settings and returned. Otherwise, {@link DefaultErrorHandler}
0 commit comments