File

src/providers/context.provider.ts

Index

Properties
Methods

Properties

Private Static Readonly _nameSpace
Type : string
Default value : 'request'

Methods

Private Static _getKeyWithNamespace
_getKeyWithNamespace(key: string)
Parameters :
Name Type Optional
key string No
Returns : string
Static get
get(key: string)
Type parameters :
  • T
Parameters :
Name Type Optional
key string No
Returns : T
Static set
set(key: string, value: any)
Parameters :
Name Type Optional
key string No
value any No
Returns : void
import * as requestContext from 'request-context';

export class ContextService {
  private static readonly _nameSpace = 'request';

  static get<T>(key: string): T {
    return requestContext.get(ContextService._getKeyWithNamespace(key));
  }

  static set(key: string, value: any): void {
    requestContext.set(ContextService._getKeyWithNamespace(key), value);
  }

  private static _getKeyWithNamespace(key: string): string {
    return `${ContextService._nameSpace}.${key}`;
  }
}

result-matching ""

    No results matching ""