.net-core Dependency Injection

前端 未结 5 824
后悔当初
后悔当初 2020-12-16 04:25

I have a Generic repository which I want to register for DI, it implements an interface IRepository.

Normally I would create an instance of it like this:

<         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 05:05

    You should be able to register the open generic with

    services.AddTransient(typeof(IRepository<>), typeof(Repository<>));
    

提交回复
热议问题