Created
October 11, 2016 14:37
-
-
Save istrau2/6191bc14052a491e74764635a7bf0a67 to your computer and use it in GitHub Desktop.
Using aurelia DI in a nodejs application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//You need to enable babel-plugin-transform-decorators-legacy in order to use @inject decorator | |
const {inject, Container} = require('aurelia-dependency-injection'); | |
const BaseController = require('../bases/BaseController'); | |
@inject(Container) | |
class AccountContactController extends BaseController { | |
constructor(container) { | |
super('AccountContact', container); | |
} | |
} | |
//Since I am using SailsJS which requires exporting an controller instance, I export this way. | |
//I figure I can manually new a controller for testing like so: new require('AccountContactController).constructor | |
module.exports = Container.instance.get(AccountContactController); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Need to add some global polyfills | |
require('aurelia-polyfills'); | |
//Make the global container available statically via Container.instance | |
//This allows us to export an object (instead of a class) if our framework wants us to export an object. | |
const di = require('aurelia-dependency-injection'); | |
const rootContainer = new di.Container(); | |
rootContainer.makeGlobal(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment