aurelia / documentation

The documentation for Aurelia.
MIT License
105 stars 111 forks source link

Dependency injection section: explicitly mention ordering of constructor params #422

Closed GimmeDaKitty closed 5 years ago

GimmeDaKitty commented 5 years ago

I am learning Aurelia and I have been bumping my head the last two days with the "xxxx is not a function" error and strange undefined and empty objects.

After much head scratching I realized that when you inject classes via the @inject decorator, these need to be specified in the same order in the constructor. I don't have a lot of experience with Javascript and come from the C# world so this was not obvious to me.

The docs say:

Notice that we use the inject decorator and that the constructor signature matches the list of dependencies in the inject decorator.

In my view this ordering should be explicitly mentioned . 'Matches the list of dependencies' does not say anything about order.

Below my specs just in case:

Library Version: aurelia-cli v1.0.1 Environment

Operating System: Windows 10

Node Version: v10.15.3

NPM Version: 6.9.0

Browser: Chrome Version 75.0.3770.100 (Official Build) (32-bit)

Language: Typescript 3.1

Loader/bundler: Webpack

3cp commented 5 years ago

Apart from the doc issue, since you are using TypeScript, you should try @autoinject which can remove the explicit deps list. It is documented in the same page you were reading.

GimmeDaKitty commented 5 years ago

@3cp yup that is indeed an option! I was just puzzled that using the normal inject didn't work! :D

EisenbergEffect commented 5 years ago

I’ll add some clarification to the docs, no problem. It’s a good point.

GimmeDaKitty commented 5 years ago

@EisenbergEffect awesome, thanks!