2.2.0 • Published 6 years ago

@jable/inject v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@jable/inject

Inject dependencies into injectable classes

Example

@Injectable()
export class Bar {
    constructor(public barProp: string = "Bar") {}
}

@Injectable()
export class Foo {
    constructor(public myString: string, public bar: Bar) {}
}

var myFoo = Injector.inject(Foo, "myString"); // Injector syntax
console.log(myFoo.myString == "myString"); // True
console.log(myFoo.bar.barProp == "Bar"); // True
myFoo.bar.barProp = "FooBar"

var myFoo2: Foo = new (<any>Foo)("mySecondString"); // TS syntax
console.log(myFoo2.myString == "mySecondString"); // True
console.log(myFoo2.bar.barProp == "FooBar"); // True

Options

/**
 * Injectable options
 * 
 * @export
 * @interface IInjectableOptions
 * @property {string} namespace Namespace of the Injectable
 * @property {{[type: string]: boolean}} exclude Excluded namespaced types, true to exclude
 * @property {boolean} inject Whether or not the class should have injectables injected into it
 */
export interface IInjectableOptions {
    namespace?: string;
    exclude?: {[type: string]: boolean};
    inject?: boolean;
}

const defaultOptions: IInjectableOptions = {
    namespace: '',
    exclude: {
        String: true,
        Number: true,
        Object: true,
        Array: true,
        Boolean: true
    },
    inject: true
}
2.2.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago