Murtuza
Murtuza

Reputation: 83

Dependency Injection UnitOfWork Pattern In Asp.Net Core

InvalidOperationException: Unable to resolve service for type 'AirlineManagement.Repository.UnitOfWork' while attempting to activate 'AirlineManagement.Controllers.StudentsController'.

What is that meaning exactly and how can i solved it??

For more info https://github.com/dotnet/core/issues/660

Upvotes: 0

Views: 893

Answers (1)

rickvdbosch
rickvdbosch

Reputation: 15571

This means your DI container is trying to construct a StudentsController, and it cannot seem to find a registration for your UnitOfWork class (or any of its dependencies).

Make sure the UnitOfWork class (or better: the interface it implements) is registered in your DI of choice, along with all other referenced interfaces/classes.

EDIT: After looking at your code, you're missing a registration for the AirlineContext. Furthermore, you're newing stuff (the AirlineRepository in UnitOfWork) while you're using DI.

I can't help but get the feeling you haven't completely understood this yet...

Upvotes: 1

Related Questions