What is `static inject ...`

I found this line of code in Aurelia Dialog

static inject = [DialogService]; 

This is the full class:

 import {Prompt} from './prompt'; import {DialogService} from '../dialog-service'; export class CommonDialogs { static inject = [DialogService]; constructor(dialogService){ this.dialogService = dialogService; } prompt(question){ return this.dialogService.open({viewModel:Prompt, model:question}); }; } 

What does static inject do? I understand that it injects a dialog service into the constructor. But why do this instead of the usual injection?

+4
source share
1 answer

Like the blog post you linked to mentions, static inject was the original way to do dependency injections. Once Babel started supporting decorators, we introduced the inject decorator to make Aurelia code a little nicer. Under the covers, it simply adds the inject property to the class at runtime ( https://github.com/aurelia/dependency-injection/blob/master/src/decorators.js#L13 ).

+6
source

All Articles