Skip to content

Instantly share code, notes, and snippets.

@oneillci
Created August 25, 2016 22:52
Show Gist options
  • Save oneillci/c0f198d668b4798b57c2176efb13c454 to your computer and use it in GitHub Desktop.
Save oneillci/c0f198d668b4798b57c2176efb13c454 to your computer and use it in GitHub Desktop.
DI inheritance
<template>
<h1>${message}</h1>
</template>
import {inject} from 'aurelia-dependency-injection';
import {Action1, Action2} from "./classes";
@inject(Action1, Action2)
export class App {
message = 'Hello World';
constructor(acn1, acn2) {
}
}
import {inject} from 'aurelia-dependency-injection';
export class Action1Dependency {
name = "one";
}
export class Action2Dependency {
name = "two";
}
export class AlwaysInjected {
name = "should always be injected";
}
@inject(AlwaysInjected)
export class ActionBase{
constructor(always) {
this.always = always;
console.log("always name is: " + this.always.name);
}
}
@inject(AlwaysInjected,Action1Dependency)
export class Action1 extends ActionBase{
constructor(alw, dep){
super(alw);
this.dep = dep;
console.log("action 1 dep name is " + dep.name);
}
}
@inject(AlwaysInjected,Action2Dependency)
export class Action2 extends ActionBase{
constructor(alw, dep){
super(alw);
this.dep = dep;
console.log("action 2 dep name is " + dep.name);
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment