My app crashes with "Unable to resolve service for type 'IOrderService' while attempting to activate 'OrderController'". The interface exists. What am I missing?
My app crashes with "Unable to resolve service for type 'IOrderService' while attempting to activate 'OrderController'". The interface exists. What am I missing?
The message means the dependency injection container was asked to build OrderController, saw that it needs IOrderService, and found no registration for it. Having the interface and class in your project is not enough; you must register them.
Fix it in Program.cs:
Then check these usual causes:
Turn on ValidateOnBuild in development to catch these when the app starts instead of at the first request.