Unable to resolve service for type while attempting to activate

后端 未结 7 935
春和景丽
春和景丽 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<IRepository, MemoryRepository>();
    

    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.

    0 讨论(0)
提交回复
热议问题