File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed
Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ export const CLASS_CONSTRUCTOR_TAG = `${PREFIX}::CLASS_CONSTRUCTOR_TAG`;
88
99export const ScopeType = {
1010 SINGLETON : `${ PREFIX } ::SINGLETON` ,
11- EXECUTION : `${ PREFIX } ::EXECUTION` ,
1211 TRANSIENT : `${ PREFIX } ::TRANSIENT` ,
1312} as const ;
1413
Original file line number Diff line number Diff line change 11import { strict as assert } from "assert" ;
22import { Container , createCustomError , ErrorType } from "../src" ;
33import { UnInjectable , Foo , Bar } from "./fixtures/items/container" ;
4- import { Config , Config2 } from "./fixtures/items/config" ;
4+ import { Config , Config2 , TransientConfig } from "./fixtures/items/config" ;
55
66
77describe ( "container.test.js" , ( ) => {
@@ -88,4 +88,20 @@ describe("container.test.js", () => {
8888 assert ( error . message . includes ( "class BB::aa => class Object" ) ) ;
8989 } ) ;
9090 } ) ;
91+
92+ describe ( "instance scope" , ( ) => {
93+ const container = new Container ( ) ;
94+ container . set ( Config ) ;
95+ container . set ( TransientConfig ) ;
96+
97+ it ( "single scope should be ok" , ( ) => {
98+ const config = container . get ( Config ) ;
99+ assert ( container . get ( Config ) === config ) ;
100+ } ) ;
101+
102+ it ( "transient scope should be ok" , ( ) => {
103+ const config = container . get ( TransientConfig ) ;
104+ assert ( container . get ( TransientConfig ) !== config ) ;
105+ } ) ;
106+ } ) ;
91107} ) ;
Original file line number Diff line number Diff line change 1- import { Injectable } from "../../../src" ;
1+ import { Injectable , ScopeType } from "../../../src" ;
22
33@Injectable ( )
44export class Config {
@@ -42,4 +42,7 @@ export class Config2 {
4242 get key ( ) {
4343 return this . #key;
4444 }
45- }
45+ }
46+
47+ @Injectable ( { scope : ScopeType . TRANSIENT } )
48+ export class TransientConfig { }
You can’t perform that action at this time.
0 commit comments