Saturday, 5 October 2019

@Inject services in other service - Nest can't resolve dependencies

I'm trying to @Inject two services into a NestJS service and am getting

Nest can't resolve dependencies of the MainServiceImpl (?, Symbol(MainDao)). Please make sure that the argument at index [0] is available in the MainModule context

Here is the service:

@Injectable()
export class MainServiceImpl implements MainService {

    constructor(
        @Inject(TYPES.PublishSubscriptionService) private publishSubscriptionService: PublishSubscriptionService,
        @Inject(TYPES.MainDao) private mainDao: MainDao
    ) {}

Now if I switch the order, it's always the second injected service that gets the error.

TYPES is an object of Symbols

const TYPES = {
    PublishSubscriptionService: Symbol('PublishSubscriptionService'),
    MainDao: Symbol('MainDao'),
};
export default TYPES;

What am I missing?

Closed NestJS issue with no resolution
NestJS doc on @Global modules



from @Inject services in other service - Nest can't resolve dependencies

No comments:

Post a Comment