# All files / core/middleware resolver.ts

100% Statements 9/9
100% Branches 0/0
100% Functions 5/5
100% Lines 8/8

    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
    1x

    1x
    1x

    1x

    1x
    1x

    1x

    1x

     import { MiddlewareContainer, MiddlewareWrapper } from './container';
    import { Injector } from '../injector/injector';
    import { Module } from '../injector/module';

    export class MiddlewareResolver {
      private readonly instanceLoader = new Injector();

      constructor(private readonly middlewareContainer: MiddlewareContainer) {}

      public async resolveInstances(module: Module, moduleName: string) {
        const middleware = this.middlewareContainer.getMiddleware(moduleName);
        await Promise.all(
          [...middleware.values()].map(
            async wrapper => this.resolveMiddlewareInstance(wrapper, middleware, module),
          ),
        );
      }

      private async resolveMiddlewareInstance(
        wrapper: MiddlewareWrapper,
        middleware: Map<string, MiddlewareWrapper>,
        module: Module,
      ) {
        await this.instanceLoader.loadInstanceOfMiddleware(
          wrapper,
          middleware,
          module,
        );
      }
    }