While attempting to activate 'BlogContextFactory'.\r\n at I was getting below exception System.InvalidOperationException: Unable to resolve service for type 'System.Func`1' Then you would fix that using the custom extension method provided by that library which would be: services.AddHttpContextAccessor() įor other packages - always read the docs. Note that some objects have their own custom ways to be registered, this is more common when you use external Nuget packages, so it pays to read the documentation for them.
So the simple fix is to change your controller to accept something that the DI container does know how to process, in this case, the interface: public BlogController(IBloggerRepository repository)
I'm guessing you just made a typo, but a fairly common one. However, your controller class is asking for the concrete class BloggerRepository and the dependency injection container doesn't know what to do when asked for that directly. That is saying whenever a IBloggerRepository is required, create a BloggerRepository and pass that in. Now look at your startup: services.AddScoped()
That is saying that your application is trying to create an instance of BlogController but it doesn't know how to create an instance of BloggerRepository to pass into the constructor. Unable to resolve service for type '' while attempting to activate ''.