Skip to content

Context is not available through dependency injection #3764

@csisy

Description

@csisy

Hello,

Just updated to Jooby 4, and noticed that the dependency injection for Provider<Context> fails.

I think I found the root cause:

  • The GuiceModule is a lateInit module
  • It creates the injector by adding JoobyModule as well
  • The JoobyModule adds the registered services to the DI container
  • The ContextAsServiceInitializer is applied by RouterImpl::start
  • The problem is that the Guice module is installed before the router is started, thus the Context provider is not yet available in the registry, thus will not be available through DI.

Do you have any suggestion how we should proceed?


We created a helper Guice module as a workaround:

public class JoobyContextGuiceModule extends AbstractModule {

    @Override
    protected void configure() {
        bind(Context.class).toProvider(ContextAsServiceInitializer.INSTANCE);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions