@naturalint/xsite-framework-context
v1.0.0
Published
Just a simple wrapper for `ni-context` package
Downloads
8
Readme
@naturalint/xsite-nest-context
Just a simple wrapper for ni-context package
How to use it in your service:
In your application module load XSiteContextModule
import { ContextMiddleware, XSiteContextModule } from '@naturalint/xsite-nest-context';
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
@Module({
imports: [XSiteContextModule],
providers: [MyService],
})
export class MyModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
consumer.apply(ContextMiddleware).forRoutes(<The routes you want>);
}
}Now, in your service you can use two different decorators:
import { Injectable } from '@nestjs/common';
import { InjectCtxId, InjectCtx } from '@naturalint/xsite-nest-context';
import { XSiteContext, ContextId } from '@naturalint/xsite-nest-context';
@Injectable()
export class MyService {
public constructor(
@InjectCtxId() private readonly ctx: XSiteContext, // Will give you the ctx id of the request
@InjectCtx() private readonly ctxId: ContextId // Will give you the full context object
) {}
}Please read more about middleware in NestJS here: https://docs.nestjs.com/middleware#middleware
