# All files / src/container InversifyContainerFacade.ts

97.22% Statements 35/36
100% Branches 0/0
100% Functions 4/4
97.22% Lines 35/36

    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
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    1111x
    1x

    1x
    1x
    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x

    1x

    1819x

    1819x

    1817x

    1819x

    1819x

    1819x

    1819x

    1816x
    1816x

    1816x

    1816x

    1819x

    1819x

    1819x
    1819x
    1819x
    1819x
    1819x
    1819x

    3630x

     import { Container, interfaces } from 'inversify';
    import { ServiceIdentifiers } from './ServiceIdentifiers';

    import { customNodesModule } from './modules/custom-nodes/CustomNodesModule';
    import { nodeControlFlowTransformersModule } from './modules/node-transformers/NodeControlFlowTransformersModule';
    import { nodeObfuscatorsModule } from './modules/node-transformers/NodeObfuscatorsModule';
    import { nodeTransformersModule } from './modules/node-transformers/NodeTransformersModule';
    import { stackTraceAnalyzerModule } from './modules/stack-trace-analyzer/StackTraceAnalyzerModule';
    import { storagesModule } from './modules/storages/StoragesModule';

    import { TInputOptions } from '../types/options/TInputOptions';

    import { IInversifyContainerFacade } from '../interfaces/container/IInversifyContainerFacade';
    import { IJavaScriptObfuscator } from '../interfaces/IJavaScriptObfsucator';
    import { IObfuscationEventEmitter } from '../interfaces/event-emitters/IObfuscationEventEmitter';
    import { IObfuscationResult } from '../interfaces/IObfuscationResult';
    import { IObfuscator } from '../interfaces/IObfuscator';
    import { IOptions } from '../interfaces/options/IOptions';
    import { ISourceMapCorrector } from '../interfaces/ISourceMapCorrector';

    import { JavaScriptObfuscatorInternal } from '../JavaScriptObfuscatorInternal';
    import { ObfuscationEventEmitter } from '../event-emitters/ObfuscationEventEmitter';
    import { ObfuscationResult } from '../ObfuscationResult';
    import { Obfuscator } from '../Obfuscator';
    import { Options } from "../options/Options";
    import { SourceMapCorrector } from '../SourceMapCorrector';

    export class InversifyContainerFacade implements IInversifyContainerFacade {
        /**
         * @type {interfaces.Container}
         */
        private readonly container: interfaces.Container;

        /**
         * @param options
         */
        constructor (options: TInputOptions) {
            this.container = new Container();

            this.container
                .bind<IOptions>(ServiceIdentifiers.IOptions)
                .toDynamicValue(() => {
                    return new Options(options);
                })
                .inSingletonScope();

            this.container
                .bind<IJavaScriptObfuscator>(ServiceIdentifiers.IJavaScriptObfuscator)
                .to(JavaScriptObfuscatorInternal)
                .inSingletonScope();

            this.container
                .bind<IObfuscator>(ServiceIdentifiers.IObfuscator)
                .to(Obfuscator)
                .inSingletonScope();

            this.container
                .bind<IObfuscationResult>(ServiceIdentifiers.IObfuscationResult)
                .to(ObfuscationResult)
                .inSingletonScope();

            this.container
                .bind<IObfuscationResult>(ServiceIdentifiers['Factory<IObfuscationResult>'])
                .toFactory<IObfuscationResult>((context: interfaces.Context) => {
                    return (obfuscatedCode: string, sourceMap: string) => {
                        const obfuscationResult: IObfuscationResult = context.container
                            .get<IObfuscationResult>(ServiceIdentifiers.IObfuscationResult);

                        obfuscationResult.initialize(obfuscatedCode, sourceMap);

                        return obfuscationResult;
                    };
                });

            this.container
                .bind<ISourceMapCorrector>(ServiceIdentifiers.ISourceMapCorrector)
                .to(SourceMapCorrector)
                .inSingletonScope();

            this.container
                .bind<IObfuscationEventEmitter>(ServiceIdentifiers.IObfuscationEventEmitter)
                .to(ObfuscationEventEmitter)
                .inSingletonScope();

            // modules
            this.container.load(storagesModule);
            this.container.load(stackTraceAnalyzerModule);
            this.container.load(customNodesModule);
            this.container.load(nodeTransformersModule);
            this.container.load(nodeControlFlowTransformersModule);
            this.container.load(nodeObfuscatorsModule);
        }

        /**
         * @param serviceIdentifier
         * @returns {T}
         */
        public get <T> (serviceIdentifier: interfaces.ServiceIdentifier<T>): T {
            return this.container.get<T>(serviceIdentifier);
        }

        /**
         * @param serviceIdentifier
         * @param named
         * @returns {T}
         */
        public getNamed <T> (serviceIdentifier: interfaces.ServiceIdentifier<T>, named: string | number | symbol): T {
            return this.container.getNamed<T>(serviceIdentifier, named);
        }
    }