Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use dependency injection in nestjs dependency injection?


Asked by Aleena Moody on Dec 02, 2021 FAQ



@Injectable () export class ProfileDomainEntity { async addAge (profileId: string, age: number): Promise<void> { const profile = await this.profilesRepository.getOne (profileId) profile.age = age await this.profilesRepository.updateOne (profileId, profile) } }
Accordingly,
Dependency injection addresses these problems through: 1 The use of an interface or base class to abstract the dependency implementation. 2 Registration of the dependency in a service container. .NET provides a built-in service container, IServiceProvider. ... 3 Injection of the service into the constructor of the class where it's used. ...
And, I'm new fairly new to all of these things (NestJs, clean architecture/DDD and Typescript as well) so I might be totally wrong here. It is not possible to resolve dependency by the interface in NestJS due to the language limitations/features (see structural vs nominal typing).
Also Know,
Dependency Injection. Client Class: The client class (dependent class) is a class which depends on the service class Service Class: The service class (dependency) is a class that provides service to the client class. Injector Class: The injector class injects service class object into the client class.
In respect to this,
Dependency Injection (DI) is awesome and helpful in setting up your projects. It’s even more awesome when you can simply port it to your Unit Tests project. .NET 5 and .NET Core 3.x