# Provider Class

Module
import { Provider } from "@tsed/di"
Source/packages/di/src/class/Provider.ts

# Overview

class Provider<T = any> implements IProvider<T> {
    type: ProviderType | any;
    injectable: boolean;
    instance: T;
    deps: TokenProvider[];
    imports: any[];
    useFactory: Function;
    useAsyncFactory: Function;
    useValue: any;
    protected _provide: TokenProvider;
    protected _useClass: Type<T>;
    protected _instance: T;
<span class="token punctuation">[</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token keyword">constructor</span><span class="token punctuation">(</span>token<span class="token punctuation">:</span> <a href="/api/di/interfaces/TokenProvider.html"><span class="token">TokenProvider</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
get <span class="token function">token</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
get <span class="token function">provide</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/di/interfaces/TokenProvider.html"><span class="token">TokenProvider</span></a><span class="token punctuation">;</span>
set <span class="token function">provide</span><span class="token punctuation">(</span>value<span class="token punctuation">:</span> <a href="/api/di/interfaces/TokenProvider.html"><span class="token">TokenProvider</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
get <span class="token function">useClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/core/interfaces/Type.html"><span class="token">Type</span></a>&lt;T&gt;<span class="token punctuation">;</span>
/**
 * Create a new store if the given value is a <span class="token keyword">class</span>. Otherwise the value is ignored.
 * @param value
 */
set <span class="token function">useClass</span><span class="token punctuation">(</span>value<span class="token punctuation">:</span> <a href="/api/core/interfaces/Type.html"><span class="token">Type</span></a>&lt;T&gt;<span class="token punctuation">)</span><span class="token punctuation">;</span>
get <span class="token function">className</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
get <span class="token function">name</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>
get <span class="token function">store</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/core/domain/Store.html"><span class="token">Store</span></a><span class="token punctuation">;</span>
/**
 * <a href="/api/common/mvc/decorators/method/Get.html"><span class="token">Get</span></a> the scope of the provider.
 *
 * <span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token punctuation">:</span> tip Note
 * Async provider is always a SINGLETON
 * <span class="token punctuation">:</span><span class="token punctuation">:</span><span class="token punctuation">:</span>
 *
 * @returns <span class="token punctuation">{</span><span class="token keyword">boolean</span><span class="token punctuation">}</span>
 */
get <span class="token function">scope</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/di/interfaces/ProviderScope.html"><span class="token">ProviderScope</span></a><span class="token punctuation">;</span>
/**
 * Change the scope value of the provider.
 * @param scope
 */
set <span class="token function">scope</span><span class="token punctuation">(</span>scope<span class="token punctuation">:</span> <a href="/api/di/interfaces/ProviderScope.html"><span class="token">ProviderScope</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
get <span class="token function">configuration</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Partial&lt;TsED.<a href="/api/di/decorators/Configuration.html"><span class="token">Configuration</span></a>&gt;<span class="token punctuation">;</span>
set <span class="token function">configuration</span><span class="token punctuation">(</span>configuration<span class="token punctuation">:</span> Partial&lt;TsED.<a href="/api/di/decorators/Configuration.html"><span class="token">Configuration</span></a>&gt;<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">get</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token function">isAsync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">boolean</span><span class="token punctuation">;</span>
<span class="token function">clone</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> Provider&lt;<span class="token keyword">any</span>&gt;<span class="token punctuation">;</span>
<span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">string</span><span class="token punctuation">;</span>

}

# Members

type: ProviderType | any;

injectable: boolean;

instance: T;

deps: TokenProvider[];

imports: any[];

useFactory: Function;

useAsyncFactory: Function;

useValue: any;

protected _provide: TokenProvider;

protected _useClass: Type<T>;

protected _instance: T;

[key: string]: any;

get token(): any;

get provide(): TokenProvider;

set provide(value: TokenProvider);

get useClass(): Type<T>;

set useClass(value: Type<T>);

Create a new store if the given value is a class. Otherwise the value is ignored.


get className(): string;

get name(): string;

get store(): Store;

get scope(): ProviderScope;

Get the scope of the provider.

Note

Async provider is always a SINGLETON

:::


set scope(scope: ProviderScope);

Change the scope value of the provider.


get configuration(): Partial<TsED.Configuration>;

set configuration(configuration: Partial<TsED.Configuration>);

get(key: string): any;

isAsync(): boolean;

clone(): Provider<any>;

toString(): string;

Other topics