Container#lookup()

lookup (fullName, options) Anyprivate

Defined in packages/container/lib/container.js:71

Given a fullName return a corresponding instance.

The default behaviour is for lookup to return a singleton instance. The singleton is scoped to the container, allowing multiple containers to all have their own locally scoped singletons.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
let registry = new Registry();
let container = registry.container();
 
registry.register('api:twitter', Twitter);
 
let twitter = container.lookup('api:twitter');
 
twitter instanceof Twitter; // => true
 
// by default the container will return singletons
let twitter2 = container.lookup('api:twitter');
twitter2 instanceof Twitter; // => true
 
twitter === twitter2; //=> true

If singletons are not wanted, an optional flag can be provided at lookup.

1
2
3
4
5
6
7
8
9
let registry = new Registry();
let container = registry.container();
 
registry.register('api:twitter', Twitter);
 
let twitter = container.lookup('api:twitter', { singleton: false });
let twitter2 = container.lookup('api:twitter', { singleton: false });
 
twitter === twitter2; //=> false

Parameters:

fullName String
options [Object]
source [String]
The fullname of the request source (used for local lookup)

Returns:

Any
doc_EmberJs
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.