-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathaurelia-dependency-injection.d.ts
688 lines (685 loc) · 33.5 KB
/
aurelia-dependency-injection.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
// Generated by dts-bundle-generator v9.5.1
export type Primitive = boolean | string | number | symbol | object | ((...args: any[]) => any) | Array<any>;
export type CtorArgs<TBase> = TBase extends new (...args: infer TArgs) => infer Impl ? TArgs : any[];
export type CtorImpl<TBase> = TBase extends new (...args: infer TArgs) => infer Impl ? Impl : any;
export type FuncArgs<TBase> = TBase extends (...args: infer TArgs) => infer Impl ? TArgs : any[];
export type FuncReturns<TBase> = TBase extends (...args: infer TArgs) => infer Impl ? Impl : any;
export type Args<TBase> = CtorArgs<TBase> | FuncArgs<TBase>;
export type Impl<TBase> = CtorImpl<TBase> | FuncReturns<TBase>;
export type DependencyCtor<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> = new (...args: TArgs) => TImpl | TBase;
export type DependencyFunctor<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> = (...args: TArgs) => TImpl | TBase;
export type ImplOrAny<TImpl> = unknown extends TImpl ? any : TImpl;
export type DependencyCtorOrFunctor<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> = DependencyCtor<TBase, TImpl, TArgs> | DependencyFunctor<TBase, TImpl, TArgs>;
export type PrimitiveOrDependencyCtor<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> = DependencyCtor<TBase, TImpl, TArgs> | Primitive;
export type PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> = DependencyCtor<TBase, TImpl, TArgs> | DependencyFunctor<TBase, TImpl, TArgs> | Primitive;
/**
* Decorator: Indicates that the decorated class/object is a custom resolver.
*/
export declare const resolver: {
decorates?: (key: any) => key is {
get(container: Container, key: any): any;
};
} & (() => any);
/**
* Used to allow functions/classes to specify custom dependency resolution logic.
*/
export interface Resolver {
/**
* Called by the container to allow custom resolution of dependencies for a
* function/class.
* @param container The container to resolve from.
* @param key The key that the resolver was registered as.
* @return Returns the resolved object.
*/
get(container: Container, key: any): any;
}
export declare enum Strategy {
instance = 0,
singleton = 1,
transient = 2,
function = 3,
array = 4,
alias = 5
}
export type IStrategy = 1 | 2 | 3 | 4 | 5;
export type StrategyFunctor<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> = (container?: Container, ctor?: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>, strategyResolver?: any) => TImpl;
export interface StrategyState<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
[Strategy.instance]: TImpl;
[Strategy.singleton]: DependencyCtorOrFunctor<TBase, TImpl, TArgs>;
[Strategy.transient]: DependencyCtorOrFunctor<TBase, TImpl, TArgs>;
[Strategy.function]: StrategyFunctor<TBase, TImpl, TArgs>;
/**
* For typings purposes, this is done as ({ get: StrategyFunctor } | TImpl)[]
* But it should be understood, and used as [{ get: StrategyFunctor }, ...TImp[]]
*/
[Strategy.array]: ({
get: (container: Container, key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>) => TImpl;
} | TImpl)[];
[Strategy.alias]: any;
}
/**
* Used to resolve instances, singletons, transients, aliases
*/
export declare class StrategyResolver<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>, TStrategyKey extends keyof StrategyState<TBase, TImpl, TArgs>> {
strategy: keyof StrategyState<TBase, TImpl, TArgs>;
state: StrategyState<TBase, TImpl, TArgs>[keyof StrategyState<TBase, TImpl, TArgs>];
/**
* Creates an instance of the StrategyResolver class.
* @param strategy The type of resolution strategy.
* @param state The state associated with the resolution strategy.
*/
constructor(strategy: TStrategyKey, state: StrategyState<TBase, TImpl, TArgs>[TStrategyKey]);
/**
* Called by the container to allow custom resolution of dependencies for a
* function/class.
* @param container The container to resolve from.
* @param key The key that the resolver was registered as.
* @return Returns the resolved object.
*/
get(container: Container, key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): TImpl;
}
/**
* Used to allow functions/classes to specify lazy resolution logic.
*/
export declare class Lazy<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
/**
* A non existent property to help TS distinguish resolvers
*
* This is semi-private, and should not be used by application
*/
__resolver_type__: "lazy";
/**
* Creates an instance of the Lazy class.
* @param key The key to lazily resolve.
*/
constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
/**
* Called by the container to lazily resolve the dependency into a lazy locator
* function.
* @param container The container to resolve from.
* @return Returns a function which can be invoked at a later time to obtain
* the actual dependency.
*/
get(container: Container): () => ImplOrAny<TImpl>;
/**
* Creates a Lazy Resolver for the supplied key.
* @param key The key to lazily resolve.
* @return Returns an instance of Lazy for the key.
*/
static of<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): Lazy<TBase, TImpl, TArgs>;
}
/**
* Used to allow functions/classes to specify resolution of all matches to a key.
*/
export declare class All<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
/**
* A non existent property to help TS distinguish resolvers
*
* This is semi-private, and should not be used by application
*/
__resolver_type__: "all";
/**
* Creates an instance of the All class.
* @param key The key to lazily resolve all matches for.
*/
constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
/**
* Called by the container to resolve all matching dependencies as an array of
* instances.
* @param container The container to resolve from.
* @return Returns an array of all matching instances.
*/
get(container: Container): TImpl[];
/**
* Creates an All Resolver for the supplied key.
* @param key The key to resolve all instances for.
* @return Returns an instance of All for the key.
*/
static of<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): All<TBase, TImpl, TArgs>;
}
/**
* Used to allow functions/classes to specify an optional dependency, which will
* be resolved only if already registred with the container.
*/
export declare class Optional<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
/**
* A non existent property to help TS distinguish resolvers
*
* This is semi-private, and should not be used by application
*/
__resolver_type__: "optional";
/**
* Creates an instance of the Optional class.
* @param key The key to optionally resolve for.
* @param checkParent Indicates whether or not the parent container hierarchy
* should be checked.
*/
constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, checkParent?: boolean);
/**
* Called by the container to provide optional resolution of the key.
* @param container The container to resolve from.
* @return Returns the instance if found; otherwise null.
*/
get(container: Container): TImpl | null;
/**
* Creates an Optional Resolver for the supplied key.
* @param key The key to optionally resolve for.
* @param [checkParent=true] Indicates whether or not the parent container
* hierarchy should be checked.
* @return Returns an instance of Optional for the key.
*/
static of<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, checkParent?: boolean): Optional<TBase, TImpl, TArgs>;
}
/**
* Used to inject the dependency from the parent container instead of the current
* one.
*/
export declare class Parent<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
/**
* A non existent property to help TS distinguish resolvers
*
* This is semi-private, and should not be used by application
*/
__resolver_type__: "parent";
/**
* Creates an instance of the Parent class.
* @param key The key to resolve from the parent container.
*/
constructor(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
/**
* Called by the container to load the dependency from the parent container
* @param container The container to resolve the parent from.
* @return Returns the matching instance from the parent container
*/
get(container: Container): TImpl | null;
/**
* Creates a Parent Resolver for the supplied key.
* @param key The key to resolve.
* @return Returns an instance of Parent for the key.
*/
static of<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): Parent<TBase, TImpl, TArgs>;
}
/**
* Used to allow injecting dependencies but also passing data to the constructor.
*/
export declare class Factory<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
/**
* A non existent property to help TS distinguish resolvers
*
* This is semi-private, and should not be used by application
*/
__resolver_type__: "factory";
/**
* Creates an instance of the Factory class.
* @param key The key to resolve from the parent container.
*/
constructor(key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>);
/**
* Called by the container to pass the dependencies to the constructor.
* @param container The container to invoke the constructor with dependencies
* and other parameters.
* @return Returns a function that can be invoked to resolve dependencies
* later, and the rest of the parameters.
*/
get(container: Container): DependencyFunctor<TBase, TImpl, TArgs>;
/**
* Creates a Factory Resolver for the supplied key.
* @param key The key to resolve.
* @return Returns an instance of Factory for the key.
*/
static of<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: DependencyCtor<TBase, TImpl, TArgs>): Factory<TBase, TImpl, TArgs>;
}
/**
* Used to inject a new instance of a dependency, without regard for existing
* instances in the container. Instances can optionally be registered in the
* container
* under a different key by supplying a key using the `as` method.
*/
export declare class NewInstance<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> {
/**
* A non existent property to help TS distinguish resolvers
*
* This is semi-private, and should not be used by application
*/
__resolver_type__: "newInstance";
/**
* Creates an instance of the NewInstance class.
* @param key The key to resolve/instantiate.
* @param dynamicDependencies An optional list of dynamic dependencies.
*/
constructor(key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>, ...dynamicDependencies: TArgs[number][]);
/**
* Called by the container to instantiate the dependency and potentially
* register
* as another key if the `as` method was used.
* @param container The container to resolve the parent from.
* @return Returns the matching instance from the parent container
*/
get(container: Container): ImplOrAny<TImpl>;
/**
* Instructs the NewInstance resolver to register the resolved instance using
* the supplied key.
* @param key The key to register the instance with.
* @return Returns the NewInstance resolver.
*/
as(key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>): this;
/**
* Creates an NewInstance Resolver for the supplied key.
* @param key The key to resolve/instantiate.
* @param dynamicDependencies An optional list of dynamic dependencies.
* @return Returns an instance of NewInstance for the key.
*/
static of<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>, ...dynamicDependencies: TArgs[number][]): NewInstance<TBase, TImpl, TArgs>;
}
/**
* Used by parameter decorators to call autoinject for the target and retrieve
* the target's inject property.
* @param target The target class.
* @return Returns the target's own inject property.
*/
export declare function getDecoratorDependencies<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(target: DependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
}): TArgs[number][] | undefined;
/**
* Decorator: Specifies the dependency should be lazy loaded
*/
export declare function lazy<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(keyValue: any): (target: {
new (...args: TArgs): TBase | TImpl;
}, _key: any, index: number) => void;
/**
* Decorator: Specifies the dependency should load all instances of the given
* key.
*/
export declare function all<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(keyValue: any): (target: DependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
}, _key: any, index: number) => void;
/**
* Decorator: Specifies the dependency as optional
*/
export declare function optional<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(checkParentOrTarget?: boolean): (target: DependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
}, _key: any, index: number) => void;
/**
* Decorator: Specifies the dependency to look at the parent container for
* resolution
*/
declare function parent$1<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(target: DependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
}, _key: any, index: number): void;
/**
* Decorator: Specifies the dependency to create a factory method, that can
* accept optional arguments
*/
export declare function factory<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(keyValue: any): (target: DependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
}, _key: any, index: number) => void;
/**
* Decorator: Specifies the dependency as a new instance. Instances can optionally be registered in the container
* under a different key and/or use dynamic dependencies
*/
export declare function newInstance<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(asKeyOrTarget?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs> & {
inject?: TArgs[number][];
}, ...dynamicDependencies: TArgs[number][]): (target: {
new (...args: any[]): any;
}, _key: any, index: number) => void;
/**
* Decorator: Specifies a custom Invoker for the decorated item.
*/
export declare function invoker<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(value: Invoker<TBase, TImpl, TArgs>): (target: DependencyCtor<TBase, TImpl, TArgs>) => void;
/**
* Decorator: Specifies that the decorated item should be called as a factory
* function, rather than a constructor.
*/
export declare function invokeAsFactory<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(potentialTarget?: DependencyCtor<TBase, TImpl, TArgs>): void | ((target: DependencyCtor<TBase, TImpl, TArgs>) => void);
/**
* A strategy for invoking a function, resulting in an object instance.
*/
export interface Invoker<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>> {
/**
* Invokes the function with the provided dependencies.
* @param fn The constructor or factory function.
* @param dependencies The dependencies of the function call.
* @return The result of the function invocation.
*/
invoke(container: Container, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>, dependencies: TArgs): ImplOrAny<TImpl>;
/**
* Invokes the function with the provided dependencies.
* @param fn The constructor or factory function.
* @param staticDependencies The static dependencies of the function.
* @param dynamicDependencies Additional dependencies to use during
* invocation.
* @return The result of the function invocation.
*/
invokeWithDynamicDependencies(container: Container, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>, staticDependencies: TArgs[number][], dynamicDependencies: TArgs[number][]): ImplOrAny<TImpl>;
}
/**
* An Invoker that is used to invoke a factory method.
*/
export declare class FactoryInvoker<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>> implements Invoker<TBase, TImpl, TArgs> {
/**
* The singleton instance of the FactoryInvoker.
*/
static instance: FactoryInvoker<any>;
/**
* Invokes the function with the provided dependencies.
* @param container The calling container.
* @param fn The constructor or factory function.
* @param dependencies The dependencies of the function call.
* @return The result of the function invocation.
*/
invoke(container: Container, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>, dependencies: TArgs): ImplOrAny<TImpl>;
/**
* Invokes the function with the provided dependencies.
* @param container The calling container.
* @param fn The constructor or factory function.
* @param staticDependencies The static dependencies of the function.
* @param dynamicDependencies Additional dependencies to use during invocation.
* @return The result of the function invocation.
*/
invokeWithDynamicDependencies(container: Container, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>, staticDependencies: TArgs[number][], dynamicDependencies: TArgs[number][]): ImplOrAny<TImpl>;
}
/**
* Stores the information needed to invoke a function.
*/
export declare class InvocationHandler<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>> {
/**
* The function to be invoked by this handler.
*/
fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>;
/**
* The invoker implementation that will be used to actually invoke the function.
*/
invoker: Invoker<TBase, TImpl, TArgs>;
/**
* The statically known dependencies of this function invocation.
*/
dependencies: TArgs;
/**
* Instantiates an InvocationDescription.
* @param fn The Function described by this description object.
* @param invoker The strategy for invoking the function.
* @param dependencies The static dependencies of the function call.
*/
constructor(fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>, invoker: Invoker<TBase, TImpl, TArgs>, dependencies: TArgs);
/**
* Invokes the function.
* @param container The calling container.
* @param dynamicDependencies Additional dependencies to use during invocation.
* @return The result of the function invocation.
*/
invoke(container: Container, dynamicDependencies?: TArgs[]): TImpl;
}
/**
* Used to configure a Container instance.
*/
export interface ContainerConfiguration {
/**
* An optional callback which will be called when any function needs an
* InvocationHandler created (called once per Function).
*/
onHandlerCreated?: (handler: InvocationHandler<any, any, any>) => InvocationHandler<any, any, any>;
handlers?: Map<any, any>;
}
/**
* A lightweight, extensible dependency injection container.
*/
export declare class Container {
/**
* The global root Container instance. Available if makeGlobal() has been
* called. Aurelia Framework calls makeGlobal().
*/
static instance: Container;
/**
* The parent container in the DI hierarchy.
*/
parent: Container | null;
/**
* The root container in the DI hierarchy.
*/
root: Container;
/**
* Creates an instance of Container.
* @param configuration Provides some configuration for the new Container instance.
*/
constructor(configuration?: ContainerConfiguration);
/**
* Makes this container instance globally reachable through Container.instance.
*/
makeGlobal(): Container;
/**
* Sets an invocation handler creation callback that will be called when new
* InvocationsHandlers are created (called once per Function).
* @param onHandlerCreated The callback to be called when an
* InvocationsHandler is created.
*/
setHandlerCreatedCallback<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(onHandlerCreated: (handler: InvocationHandler<TBase, TImpl, TArgs>) => InvocationHandler<TBase, TImpl, TArgs>): void;
/**
* Registers an existing object instance with the container.
* @param key The key that identifies the dependency at resolution time;
* usually a constructor function.
* @param instance The instance that will be resolved when the key is matched.
* This defaults to the key value when instance is not supplied.
* @return The resolver that was registered.
*/
registerInstance<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, instance?: TImpl): Resolver;
/**
* Registers a type (constructor function) such that the container always
* returns the same instance for each request.
* @param key The key that identifies the dependency at resolution time;
* usually a constructor function.
* @param fn The constructor function to use when the dependency needs to be
* instantiated. This defaults to the key value when fn is not supplied.
* @return The resolver that was registered.
*/
registerSingleton<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: Primitive, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
registerSingleton<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: DependencyCtor<TBase, TImpl, TArgs>, fn?: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
/**
* Registers a type (constructor function) such that the container returns a
* new instance for each request.
* @param key The key that identifies the dependency at resolution time;
* usually a constructor function.
* @param fn The constructor function to use when the dependency needs to be
* instantiated. This defaults to the key value when fn is not supplied.
* @return The resolver that was registered.
*/
registerTransient<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: Primitive, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
registerTransient<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: DependencyCtor<TBase, TImpl, TArgs>, fn?: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
/**
* Registers a custom resolution function such that the container calls this
* function for each request to obtain the instance.
* @param key The key that identifies the dependency at resolution time;
* usually a constructor function.
* @param handler The resolution function to use when the dependency is
* needed.
* @return The resolver that was registered.
*/
registerHandler<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, handler: (container?: Container, key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, resolver?: Resolver) => any): Resolver;
/**
* Registers an additional key that serves as an alias to the original DI key.
* @param originalKey The key that originally identified the dependency; usually a constructor function.
* @param aliasKey An alternate key which can also be used to resolve the same dependency as the original.
* @return The resolver that was registered.
*/
registerAlias<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(originalKey: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, aliasKey: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): Resolver;
/**
* Registers a custom resolution function such that the container calls this
* function for each request to obtain the instance.
* @param key The key that identifies the dependency at resolution time;
* usually a constructor function.
* @param resolver The resolver to use when the dependency is needed.
* @return The resolver that was registered.
*/
registerResolver<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, resolver: Resolver): Resolver;
/**
* Registers a type (constructor function) by inspecting its registration
* annotations. If none are found, then the default singleton registration is
* used.
* @param key The key that identifies the dependency at resolution time;
* usually a constructor function.
* @param fn The constructor function to use when the dependency needs to be
* instantiated. This defaults to the key value when fn is not supplied.
*/
autoRegister<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: Primitive, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
autoRegister<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: DependencyCtor<TBase, TImpl, TArgs>, fn?: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
/**
* Registers an array of types (constructor functions) by inspecting their
* registration annotations. If none are found, then the default singleton
* registration is used.
* @param fns The constructor function to use when the dependency needs to be instantiated.
*/
autoRegisterAll(fns: DependencyCtor<any, any, any>[]): void;
/**
* Unregisters based on key.
* @param key The key that identifies the dependency at resolution time; usually a constructor function.
*/
unregister(key: any): void;
/**
* Inspects the container to determine if a particular key has been registred.
* @param key The key that identifies the dependency at resolution time; usually a constructor function.
* @param checkParent Indicates whether or not to check the parent container hierarchy.
* @return Returns true if the key has been registred; false otherwise.
*/
hasResolver<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, checkParent?: boolean): boolean;
/**
* Gets the resolver for the particular key, if it has been registered.
* @param key The key that identifies the dependency at resolution time; usually a constructor function.
* @return Returns the resolver, if registred, otherwise undefined.
*/
getResolver<TStrategyKey extends keyof StrategyState<TBase, TImpl, TArgs>, TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtorOrFunctor<TBase, TImpl, TArgs>): StrategyResolver<TBase, TImpl, TArgs, TStrategyKey>;
/**
* Resolves a single instance based on the provided key.
* @param key The key that identifies the object to resolve.
* @return Returns the resolved instance.
*/
get<TBase, TResolver extends NewInstance<TBase> | Lazy<TBase> | Factory<TBase> | Optional<TBase> | Parent<TBase> | All<TBase>>(key: TResolver): ResolvedValue<TResolver>;
get<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): ImplOrAny<TImpl>;
get<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: typeof Container): Container;
_get(key: any): any;
/**
* Resolves all instance registered under the provided key.
* @param key The key that identifies the objects to resolve.
* @return Returns an array of the resolved instances.
*/
getAll<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): ImplOrAny<TImpl>[];
/**
* Creates a new dependency injection container whose parent is the current container.
* @return Returns a new container instance parented to this.
*/
createChild(): Container;
/**
* Invokes a function, recursively resolving its dependencies.
* @param fn The function to invoke with the auto-resolved dependencies.
* @param dynamicDependencies Additional function dependencies to use during invocation.
* @return Returns the instance resulting from calling the function.
*/
invoke<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>, dynamicDependencies?: TArgs[number][]): ImplOrAny<TImpl>;
_createInvocationHandler<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs> & {
inject?: any;
}): InvocationHandler<TBase, TImpl, TArgs>;
}
export type ResolvedValue<T> = T extends (new (...args: any[]) => infer R) ? R : T extends (abstract new (...args: any[]) => infer R) ? R : T extends Factory<infer R> ? (...args: unknown[]) => R : T extends Lazy<infer R> ? () => R : T extends NewInstance<infer R> ? R : T extends Optional<infer R> ? R | null : T extends All<infer R> ? R[] : T extends Parent<infer R> ? R | null : T extends [
infer T1,
...infer T2
] ? [
ResolvedValue<T1>,
...ResolvedValue<T2>
] : T;
/**
* Resolve a key, or list of keys based on the current container.
*
* @example
* ```ts
* import { resolve } from 'aurelia-framework';
* // or
* // import { Container, resolve } from 'aurelia-dependency-injection';
*
* class MyCustomElement {
* someService = resolve(MyService);
* }
* ```
*/
export declare function resolve<K extends any>(key: K): ResolvedValue<K>;
export declare function resolve<K extends any[]>(...keys: K): ResolvedValue<K>;
export type Injectable = Function & {
inject?: any[] | (() => any[]);
};
/**
* Decorator: Directs the TypeScript transpiler to write-out type metadata for
* the decorated class.
*/
export declare function autoinject<TPotential>(potentialTarget?: TPotential): TPotential extends Injectable ? void : (target: Injectable) => void;
/**
* Decorator: Specifies the dependencies that should be injected by the DI Container into the decorated class/function.
*/
export declare function inject<TBase, TImpl extends Impl<TBase> = Impl<TBase>, TArgs extends Args<TBase> = Args<TBase>>(...rest: TArgs[number][]): any;
/**
* Decorator: Specifies a custom registration strategy for the decorated
* class/function.
*/
export declare function registration<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(value: Registration<TBase, TImpl, TArgs>): (target: DependencyCtor<TBase, TImpl, TArgs>) => void;
/**
* Decorator: Specifies to register the decorated item with a "transient"
* lifetime.
*/
export declare function transient<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>): (target: DependencyCtor<TBase, TImpl, TArgs>) => void;
/**
* Decorator: Specifies to register the decorated item with a "singleton"
* lifetime.
*/
export declare function singleton(registerInChild?: boolean): any;
export declare function singleton<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>>(key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, registerInChild?: boolean): any;
/**
* Customizes how a particular function is resolved by the Container.
*/
export interface Registration<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>> {
/**
* Called by the container to register the resolver.
* @param container The container the resolver is being registered with.
* @param key The key the resolver should be registered as.
* @param fn The function to create the resolver for.
* @return The resolver that was registered.
*/
registerResolver(container: Container, key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
}
/**
* Used to allow functions/classes to indicate that they should be registered as
* transients with the container.
*/
export declare class TransientRegistration<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>> implements Registration<TBase, TImpl, TArgs> {
/**
* Creates an instance of TransientRegistration.
* @param key The key to register as.
*/
constructor(key?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>);
/**
* Called by the container to register the resolver.
* @param container The container the resolver is being registered with.
* @param key The key the resolver should be registered as.
* @param fn The function to create the resolver for.
* @return The resolver that was registered.
*/
registerResolver(container: Container, key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
}
/**
* Used to allow functions/classes to indicate that they should be registered as
* singletons with the container.
*/
export declare class SingletonRegistration<TBase, TImpl extends Impl<TBase>, TArgs extends Args<TBase>> implements Registration<TBase, TImpl, TArgs> {
/**
* Creates an instance of SingletonRegistration.
* @param key The key to register as.
*/
constructor(keyOrRegisterInChild?: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs> | boolean, registerInChild?: boolean);
/**
* Called by the container to register the resolver.
* @param container The container the resolver is being registered with.
* @param key The key the resolver should be registered as.
* @param fn The function to create the resolver for.
* @return The resolver that was registered.
*/
registerResolver(container: Container, key: PrimitiveOrDependencyCtor<TBase, TImpl, TArgs>, fn: DependencyCtorOrFunctor<TBase, TImpl, TArgs>): Resolver;
}
export {
parent$1 as parent,
};
export {};