Dependency Injection In .Net Web Api
Ravi Rajput
Software Engineer | Angular Expert | ReactJs | Javascript | C# | DotNet Core |.net Maui | DevOps | Fullstack Developer
Day 3/75, In Dot Net How to configure and create Dependency injection in Controller and Service Layer?
first of all, create folders and make folder structure,
In Controller- we create dependency and making our API.
In Service Layer- here Is Business logic, validation.
In Common Layer (inside Model)- In model we define the request body and response body in Model.
IN Repository Layer- Main code of APIs in Repository Layer.
Now create Dependency in blow Screenshots, after that how to configure in program.cs this one screenshot in below.
Why We Use Dependency Injection ---The main advantage of DI (Dependency Injection) is our application is loosely coupled and has provided greater maintainability, testability, and also re-usability.
It is loosely coupled because dependency required by the class is injected from the outer world rather than created themselves directly win-in code.
I hope this first Article Help You
By Ravi Rajput
Need Your Support, Do Like and Share ????