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

[inversify-express-utils] - No support for @controller on inevrfisy-binding-decorators? #359

Open
jonit-dev opened this issue May 25, 2021 · 1 comment

Comments

@jonit-dev
Copy link

Hey folks, I'm trying to implement here the inversify-binding-decorators together with the inversify-express-utils lib. Unfortunately, I wasn't didn't manage to make my @controller bindings to work properly. They do not seem to be recognized and I'm having to load all of them through a container.load

for example:

container.load(
  buildProviderModule(),
  assetControllerContainer,
  collectionControllerContainer,
  userControllerContainer,
  trackerControllerContainer,
  quoteControllerContainer,
  indicatorControllerContainer,
  portfolioControllerContainer,
  companyControllerContainer,
  orderControllerContainer,
  newsControllerContainer
);

Expected Behavior

I was expecting to add a @provide() on any of my controllers and it's automatically bound into my inversify container, so I don't need to load all of them manually with container.load (like above)

Current Behavior

Any @provide(CLASSNAMEHERE) on my controllers simply leads to a unbound controller (route throws a 404)

Possible Solution

A temporary workaround is binding modules manually and them loading them on container.load.

For example:

export const assetControllerContainer = new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind) => {
  bind<CreateAssetController>(CreateAssetController).toSelf();
  bind<FilterAssetController>(FilterAssetController).toSelf();
  bind<ReadAssetController>(ReadAssetController).toSelf();
});

then

container.load(
  buildProviderModule(),
  assetControllerContainer,
  ....
);

@PodaruDragos
Copy link
Member

Yes. the controllers should be manually imported in your ioc file. I know this is not ideal
PR's are welcomed to fix this

@PodaruDragos PodaruDragos transferred this issue from inversify/InversifyJS Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants