Dependency Injection (IoC)
Problem: I required a custom entity to be returned as my LINQ involved a lot of grouping and, summation from various tables, however, the repository layer, can have only entities (objects which represent a table in the database) and we don’t use Data Transfer Objects in the repository layer. I had two options either return the List of required entities and combine the lists together in the service layer or use Dependency Injection!
I picked Dependency Injection as it was a more optimal solution for my problem. After playing around with Unity and watching this video, I was finally able to connect the blocks together on how its used.
I made an interface of the object, used that in my repository layer and returned the interface instead of an custom object.


I implemented a Dto which inherited the details from the interface IObject, and, using Unity, I mapped everything together.
Instead of creating a model that fetches the contents from the database, I pushed the data using Unity into the model.
Dependency Inversion Principle-
It decouples the construction of your classes from the construction of its dependencies.
It is the principle that code should depend on abstractions rather than dependencies. In the above example, instead of creating an instance, we created an interface, we decoupled our implementations from each other.