How to use the typedi.of function in typedi

To help you get started, we’ve selected a few typedi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MichalLytek / type-graphql / examples / using-scoped-container / index.ts View on Github external
context: (): Context => {
      const requestId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); // uuid-like
      const container = Container.of(requestId); // get scoped container
      const context = { requestId, container }; // create our context
      container.set("context", context); // place context or other data in container
      return context;
    },
    // create a plugin that will allow for disposing the scoped container created for every request
github w3tecch / express-typescript-boilerplate / src / loaders / graphqlLoader.ts View on Github external
expressApp.use(env.graphql.route, (request: express.Request, response: express.Response) => {

            // Build GraphQLContext
            const requestId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); // uuid-like
            const container = Container.of(requestId); // get scoped container
            const context = { requestId, container, request, response }; // create our context
            container.set('context', context); // place context or other data in container

            // Setup GraphQL Server
            GraphQLHTTP({
                schema,
                context,
                graphiql: env.graphql.editor,
                formatError: error => ({
                    code: getErrorCode(error.message),
                    message: getErrorMessage(error.message),
                    path: error.path,
                }),
            })(request, response);
        });
github birkir / prime / packages / prime-core / src / modules / index.ts View on Github external
context(context) {
      const requestId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
      const container = Container.of(requestId);
      const ctx = {
        requestId,
        container,
      };
      container.set('context', ctx);
      return ctx;
    },
    logger: {
github birkir / prime / packages / prime-core / src / modules / internal / index.ts View on Github external
async context(session, currentContext) {
      const requestId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
      const container = Container.of(requestId);

      const ctx = {
        requestId,
        container,
        user: ((session || {}) as any).user,
        ability: createAbility(currentContext),
      };

      container.set('context', ctx);
      return ctx;
    },
    resolversComposition: {
github birkir / prime / packages / prime-core / src / modules / external / index.ts View on Github external
async context(session, currentContext) {
      const { req } = session;
      const requestId = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
      log('requestId', requestId);
      const container = Container.of(requestId);
      const ctx: { [key: string]: any } = {
        requestId,
        container,
      };

      if (req.headers[PRIME_TOKEN]) {
        const server = AccountsModule.injector.get(AccountsServer);
        ctx.userSession = await server.findSessionByAccessToken(req.headers[PRIME_TOKEN]);
        if (!ctx.userSession) {
          throw new AuthenticationError('Token not valid');
        }

        if (req.headers[PRIME_PREVIEW]) {
          ctx.preview = await getRepository(Document).findOneOrFail(req.headers[PRIME_PREVIEW]);
        }
      }