Unable to resolve service for type while attempting to activate

后端 未结 7 957
春和景丽
春和景丽 2020-12-09 02:22

I have one file Repository.cs that contains an interface and its implementation like so:

public interface IRepository

{
    IEnumerable

        
7条回答
  •  再見小時候
    2020-12-09 03:06

    You need to register IRepository with the Dependency Injection framework. For example, in ConfigureServices, add the following:

    services.AddScoped();
    

    AddScoped is just one example of a service lifetime. Note that:

    Scoped lifetime services are created once per request.

    See the docs for more information on Dependency Injection in ASP.NET Core.

提交回复
热议问题