Created
January 27, 2016 04:35
-
-
Save sylvain-hamel/332aeba3d9e65075c539 to your computer and use it in GitHub Desktop.
aurelia scoped instance using autoRegistrer
This file contains hidden or 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
import {Container, singleton} from 'aurelia-dependency-injection'; | |
describe('DI scoped singletong', () => { | |
@singleton(true) | |
class Foo{} | |
it('should work the way I think :)', () => { | |
let rootContainer = new Container(); | |
let rootSingleton = rootContainer.get(Foo) | |
let rootSingletonB = rootContainer.get(Foo) | |
let childContainer1 = rootContainer.createChild(); | |
childContainer1.autoRegister(Foo); | |
let childContainer1singleton = childContainer1.get(Foo) | |
let childContainer11 = childContainer1.createChild(); | |
let childContainer11singleton = childContainer11.get(Foo) | |
let childContainer2 = rootContainer.createChild(); | |
childContainer2.autoRegister(Foo); | |
let childContainer2singleton = childContainer2.get(Foo) | |
let childContainer22 = childContainer2.createChild(); | |
let childContainer22singleton = childContainer22.get(Foo) | |
expect(rootSingletonB).toBe(rootSingleton, '1 - roots shoud be same object'); | |
expect(childContainer1singleton).not.toBe(rootSingleton, '2 - scope singleton should not be same as root'); | |
expect(childContainer2singleton).not.toBe(rootSingleton, '3 - scope singleton should not be same as root'); | |
expect(childContainer11singleton).toBe(childContainer1singleton, '4 - inner scope singleton be same as outer'); | |
expect(childContainer22singleton).toBe(childContainer2singleton, '5 - inner scope singleton be same as outer'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment