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