Skip to content

An Aurelia Dependency Injection plugin to inject dependencies into instance properties.

License

Notifications You must be signed in to change notification settings

devaur/aurelia-property-injection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aurelia-property-injection

npm version CircleCI

This plugin enables the core Aurelia's DI Container to inject dependencies into class instance properties, lifting the constructor from being the dependency bearer and decoupling child classes from parent dependencies.

The implementation follows the Convention over configuration paradigm, assuming the presence of a static injectProperties enumeration of property: Type to satisfy dependencies. For example, having a class like this:

import {Router} from 'aurelia-router';

export class MyClass {

  static injectProperties = {
    router: Router
  };

}

the container will produce an instance of MyClass with the current Router available in the router property.

It also provides extended implementations of the core inject and autoinject decorators, e.g.

import {inject} from 'aurelia-property-injection';
import {Router} from 'aurelia-router';

export class MyClass {

  @inject(Router)
  router;

}

and for TypeScript

import {autoinject} from 'aurelia-property-injection';

export class MyClass {

  @autoinject
  private router: Router;

}

Installing the plugin

Install the plugin via NPM:

npm install --save aurelia-property-injection

Enabling the plugin

To enable the plugin, simply use it in the Aurelia's main configuration of your application:

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .plugin('aurelia-property-injection');

  aurelia.start().then(() => aurelia.setRoot());
}

About

An Aurelia Dependency Injection plugin to inject dependencies into instance properties.

Resources

License

Stars

Watchers

Forks

Packages

No packages published