Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example outputs "Service not decorated" Error #5

Closed
snnsnn opened this issue Jan 19, 2022 · 2 comments
Closed

Example outputs "Service not decorated" Error #5

snnsnn opened this issue Jan 19, 2022 · 2 comments

Comments

@snnsnn
Copy link

snnsnn commented Jan 19, 2022

Hi, I tried to follow an example from the documentation but got Error: Service not decorated: ServiceOne. I could not figure out the problem.

I turned on the decorators support in tsconfig.jscon:

{
  "emitDecoratorMetadata": true,
   "experimentalDecorators": true,
}
import 'reflect-metadata';
import { ContainerBuilder, Service } from 'diod';

@Service()
export class ServiceOne {
  constructor(
    private readonly dep1: ServiceTwo,
    private readonly dep2: ServiceThree
  ) {}
}

@Service()
export class ServiceTwo {
  constructor(private readonly dep1: ServiceFour) {}
}

@Service()
export class ServiceThree {}

@Service()
export class ServiceFour {}

const builder = new ContainerBuilder();

builder.registerAndUse(ServiceOne);
builder.registerAndUse(ServiceTwo);
builder.registerAndUse(ServiceThree);
builder.registerAndUse(ServiceFour);

const container = builder.build();
const serviceOne = container.get(ServiceOne);
const serviceTwo = container.get(ServiceTwo);
const serviceThree = container.get(ServiceThree);
const serviceFour = container.get(ServiceFour);

console.log({ serviceOne, serviceTwo, serviceThree, serviceFour });

The error is:

throw new Error(`Service not decorated: ${[...parents, target.name].join(" -> ")}`);

Error: Service not decorated: ServiceOne
    at getDependenciesFromDecoratedServiceOrThrow 
    ...
@snnsnn
Copy link
Author

snnsnn commented Jan 19, 2022

Turns out compiler did not include the reflect-metadata module.

@snnsnn snnsnn closed this as completed Jan 19, 2022
@artberri
Copy link
Owner

Ok @snnsnn 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants