All files / lib/chainingOptions InstantiationModeCO.ts

95% Statements 19/20
100% Branches 0/0
87.5% Functions 7/8
94.73% Lines 18/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 5012x 12x 12x 12x       12x         110x 110x 110x       1x 1x       1x 1x       11x               5x 3x       5x 5x       2x      
import { ChainingOptions } from "./ChainingOptions";
import { AsPrototypeCO } from "./AsPrototypeCO";
import { AsFactoryResultCO } from "./AsFactoryResultCO";
import { AsFactoryCO } from "./AsFactoryCO";
import { Container } from "../Container";
import { IInstantiatable } from "../interfaces/IInstantiatable";
 
export class InstantiationModeCO {
 
    private instantiable: IInstantiatable;
    private chainingOptions: ChainingOptions;
 
    constructor(private readonly container: Container, private readonly key: string) {
        this.instantiable = this.container.definitionsRepository.getDefinition(key);
        this.chainingOptions = new ChainingOptions(container, key);
    }
 
    asPrototype(): AsPrototypeCO {
        this.chainingOptions.asPrototype();
        return new AsPrototypeCO(this.container, this.key);
    }
 
    asSingleton(): AsPrototypeCO {
        this.chainingOptions.asSingleton();
        return new AsPrototypeCO(this.container, this.key);
    }
 
    asConstant(): void {
        this.chainingOptions.asConstant();
    }
 
    addTags(tags: string[]) {
        this.chainingOptions.addTags(tags);
    }
 
    asFactoryResult(factoryKey: string): AsFactoryResultCO {
        this.chainingOptions.asFactoryResult(factoryKey);
        return new AsFactoryResultCO(this.container, this.key);
    }
 
    asFactory(factoryFn?: string): AsFactoryCO {
        this.chainingOptions.asFactory(factoryFn);
        return new AsFactoryCO(this.container, this.key);
    }
 
    withContext(context: {}): void {
        this.chainingOptions.withContext(context);
    }
}