reactant-di
Version:
A dependency injection lib for Reactant
43 lines • 1.07 kB
TypeScript
import { ServiceIdentifierOrFunc } from '../interfaces';
/**
* ## Description
*
* You can use `@inject()` to perform the required dependency injection module to decorate in the constructor of an injectable class.
*
* If the default is a dependency injection of the class itself as a type, e.g. `@inject(Foo) foo: Foo`, then it is exactly the same as `foo: Foo`.
*
* ## Example
*
* ```ts
* @injectable()
* class Bar {
* getValue() {
* return 'bar';
* }
* }
*
* @injectable()
* class Foo {
* getValue() {
* return 'foo';
* }
* }
*
* @injectable()
* class FooBar {
* constructor(@inject() public bar: Bar, @inject('foo') public foo: Foo) {}
* }
*
* const fooBar = testBed({
* modules: [
* Bar,
* { provide: 'foo', useClass: Foo },
* ],
* main: FooBar,
* });
*
* expect(fooBar.instance.foo.getValue()).toBe('foo');
* ```
*/
export declare function inject(serviceIdentifierOrFunc?: ServiceIdentifierOrFunc<any>): (target: object, key?: string, index?: number) => void;
//# sourceMappingURL=inject.d.ts.map