Skip to content

question: receiving ServiceNotFoundError after trying basic example from documentation #281

Open
@alanlee8421

Description

@alanlee8421
const AlanService = require('../../services/alan/alan.service');
const Container = require('typedi').Container;

exports.readAll = async (req, res, next) => {
  try {
    const alanService = Container.get(AlanService);
    const result = await alanService.alan();
    responseJson(req, res, result);
  } catch (error) {
    console.error(error);
    errorHandler(req, res, error, next);
  }
};

error log:

ServiceNotFoundError: Service with "MaybeConstructable<AlanService>" identifier was not found in the container. Register it before usage via explicitly calling the "Container.set" function or using the "@Service()" decorator.

This error occurs after version 0.8.0.

Your guide explains that when a service is used as above, it checks for the existence of an instance and creates or retrieves it when .get is called. And the above code worked normally until 0.8.0. Can you explain how the usage has changed from the next version?

스크린샷 2021-04-01 오후 12 36 09

Your official document also doesn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs docsIssues or PRs which still need documentation added.type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions