-
Notifications
You must be signed in to change notification settings - Fork 404
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
fix: TypeDI integration not working as expected on docs #642
Comments
Hi! This is the expected behavior. Since TypeDI 0.9.0 it won't create instances for unknown classes, so you need to decorate your classes. This needs to be documented and also I believe a fix is possible as routing-controller can auto-register them in its own decrator. |
Hey Thanks for the answer, I'll make a pull request tonight to add some documentation about this ! |
I hate to ask, but: how does something like this sound when the developer says it out loud?
A meme for the ages. Services everywhere. |
Still no solution yet for not having to put @service() on all classes? |
Hi, I have the same problem now, how do I solve it?
NodeJs: 16.0.0 index.ts
controller.ts
service.ts
|
@jenya-yacovets Please take some time to investigate before asking someone to do your job. 😉 It seems like your ErrorHandlerMiddleware "Service" isn't found in Container, but since you didn't provide any part of this code, I can just guess that you forgot adding the |
Thanks! I thought that only in controllers you need to specify @service() |
This is what I'm using to save me from writing more code than necessary 😁 : export function ServiceController(...args: Parameters<typeof Controller>) {
return <TFunction extends Function>(target: TFunction) => {
Service()(target);
Controller(...args)(target);
};
}
export function ServiceJsonController(...args: Parameters<typeof Controller>) {
return <TFunction extends Function>(target: TFunction) => {
Service()(target);
JsonController(...args)(target);
};
} |
I had to update ~60 classes to add |
it is also odd how semver is handled in the related libs - breaking changes like this require a major bump or a graceful behavior as stated in the comment #642 (comment) |
@aaarichter In SemVer, going from version 0.x.y to 0.x+1.0 is considered a major bump. NPM also handles it as such, e.g. depending on |
@NoNameProvided I believe this has been solved. Package is working as expected. I agree that controllers should maybe register themselves in the DI without the explicit @service decorator but that's a feature request at this point. |
Let's keep this open for tracking. I think we may auto-register services, but we need to discuss this further. |
Update: they are the same... even TSyringe still require us to apply |
Any update on this? |
The issue with auto registering is that we have to commit to one di lib, otherwise we cannot really register the controllers because each lib instantiates the services differently. One solution could be to provide a configurable function in the factories where you can set how you want your controllers instantiated, but we would have to resolve the dependencies ourselves then. |
Description
Cannot use TypeDI as explained on the README for basic services.
Obviously, it is written that it only requires the
@Service
on service side (seems legit), but this actually doesn't work without telling@Service
before the controller as well.Minimal code-snippet showcasing the problem
Controller snippet
Actual service snippet
Expected behavior
I've imported everything and created the DI Container before the app, the Controller should be working without the
@Service
decorator declaration.Actual behavior
It doesn't, if I try to run the code without the
@Service
decorator on top of the Controller, I'll get the following error:I don't know if this is an upstream issue or not.
The text was updated successfully, but these errors were encountered: