dino-core
Version:
A dependency injection framework for NodeJS applications
108 lines (107 loc) • 5.91 kB
TypeScript
import { type ApplicationContext } from '../context/ApplicationContext';
import { ComponentDescriptor } from './ComponentDescriptor';
import { Injectable } from './injectable';
import { Resolver } from './resolver';
import { Scope } from './scope';
/**
* A configuration allows to provide component descriptors that describe Injectables that may need additional configuration or that are
* external to the application core
*
* When contextScan is set to true, classes extending this class will be
* automatically discovered and injected on the application context.
* @typedef {Configuration}
*
* @public
* @abstract
*/
export declare abstract class Configuration extends Injectable {
protected readonly applicationContext: ApplicationContext;
constructor({ applicationContext }: {
applicationContext: any;
});
/**
* Create a component descriptor to be used to register the value defined on this configuration on the application context.
*
* @param {String|Component} value the {String|Component} value to register on the application context
* @param {Scope} scope the {@link Scope} that the newly registered component should have defaults to {@link Scope.SINGLETON}
* @param {Resolver} resolver the {@link Resolver} that the newly registered component should have defaults to {@link Resolver.CLASS}
* @param {String} name the name to assign to the component at resolution time, it will be converted as a camel-case,
* will be inferred from `value.name` if undefined
*
* @returns {ComponentDescriptor} the {@link ComponentDescriptor} to use for resolution
*
* @deprecated use any of {ComponentDescriptor#createFromValue} or {ComponentDescriptor#createFromImport} or {ComponentDescriptor#createFromType} methods
* @public
*/
asComponentDescriptor<T extends Injectable>(value: string | T, scope?: Scope, resolver?: Resolver, name?: string | undefined): ComponentDescriptor;
/**
* Create a component descriptor to be used to register the value defined on this configuration on the application context.
*
* @param {Component} value the value to register on the application context
* @param {String} scope the scope of the component, can be one of:
* - **transient**: a new instance of the component will be created ond injected when required
* - **singleton**: a single component instance will be create and reused every time is required
* - **scoped**: The registration is scoped to the container - that means that the resolved value
*
* @deprecated use {@link Configuration.asComponentDescriptor} as `Configuration.asComponentDescriptor(component, scope, Resolver.VALUE)` instead
* @public
*
*/
asComponentDescriptorWithScope(value: Injectable, scope: Scope): ComponentDescriptor;
/**
* Create a component descriptor to be used to register the value defined on this configuration on the application context.
*
* @param {Component} value the value to register on the application context
* @param {String} name the name of the value component to use it will be used as a primary reference, if not provided
* the framework will try to read the name from the value property of the provided component.
*
* @deprecated use {@link Configuration.asComponentDescriptor} as `Configuration.asComponentDescriptor(component, Scope.SINGLETON, Resolver.VALUE, name)` instead
* @public
*/
createValueTypeComponentDescriptor(value: Injectable, name: string): ComponentDescriptor;
/**
* Create a component descriptor to be used to register the value defined on this configuration on the application context.
*
* @param {Component} value the value to register on the application context
* @param {String} name the name of the value component to use it will be used as a primary reference, if not provided
* the framework will try to read the name from the value property of the provided component.
* @param {String} scope the scope of the component, can be one of:
* - **transient**: a new instance of the component will be created ond injected when required
* - **singleton**: a single component instance will be create and reused every time is required
* - **scoped**: The registration is scoped to the container - that means that the resolved value
*
* @deprecated use {@link Configuration.asComponentDescriptor} as `Configuration.asComponentDescriptor(component, scope, Resolver.VALUE, name)` instead
* @public
*/
createValueTypeComponentDescriptorWithScope(value: Injectable, name: string, scope: Scope): ComponentDescriptor;
/**
* Requires a component and register it as part of the application context
*
* @param {String} component the path of the component to require
*
* @public
*/
require(component: string): void;
getTypeName(): string;
/**
* Allows to provide configuration for specific areas of the applications.
* the result of the invocation of the configure method will be registered on the
* application context as-is and made available for injection.
*
* **This method must return a ComponentDescriptor, the recommended way to do that is to
* use the Configuration#asComponentDescriptor method made available on this class.**
*
* An example of implementation of the configure function is provided below
```javascript
configure() {
let myComponent = new MyDbConnectorComponent();
return this.asComponentDescriptor('myDbComponentDescriptor', myComponent);
}
```
*
* @returns {ComponentDescriptor | Promise<ComponentDescriptor>} the object to be set on the configuration
*
* @public
*/
abstract configure(): ComponentDescriptor | Promise<ComponentDescriptor>;
}