Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Container not initialised when used in bootstrap #1069

Open
aminmc opened this issue Mar 9, 2019 · 0 comments
Open

[Question] Container not initialised when used in bootstrap #1069

aminmc opened this issue Mar 9, 2019 · 0 comments

Comments

@aminmc
Copy link

aminmc commented Mar 9, 2019

Hello,

Apologies if this isn't the right place to ask this but I'm stuck on the following scenario:

I have a class that initialises a container and do the following:

 this.container.load(buildProviderModule());

In my bootstrap class I try to get a service class from the container:

const applicationContext: ApplicationContext = new ApplicationContext();

const container = applicationContext.iocContainer();

const server = new InversifyExpressServer(container);

server.setConfig((app) => {
    const keycloakService: KeycloakService = container.get(TYPE.KeycloakService);
    app.use(keycloakService.middleware());
    app.use(bodyParser.urlencoded({
        extended: true,
    }));
    app.use(bodyParser.json());
});

When I start my bootstrap class I get the following exception:

Error: No matching bindings found for serviceIdentifier: Symbol(KeycloakService)
    at _validateActiveBindingCount (/Users/aminmc/Development/typescript-example/node_modules/inversify/lib/planning/planner.js:62:23)

If I explicitly add the class to the container then it works.

  this.container.bind<KeycloakService>(TYPE.KeycloakService).to(KeycloakService);

My service class looks

@provide(TYPE.KeycloakService)
export class KeycloakService {
..
}

It looks as though the KeycloakService hasn't been registered by the time I call the container to get the class. The Keycloak Service resides in a different package from the ApplicationContext class where I initialise the container.

Is there a way force the container to be initialised before I call the container to get the class? Or am I missing a set up method?

Any help would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant