简体   繁体   中英

Web API ASP.NET Dependency injection

I've started looking into Web API 2.2. I understand the concepts and the purpose of this framework.

I was having some issues with Dependency Injection yesterday and found a resolution to the problem.

My question is, do I really need to create a interface for all my classes? I would have to create so many interfaces.

I am using Entity framework and there is a lot of tables. I find it very hard to believe that I really need to create an interface for each table in order to perfrom CRUD operations.

Isn't there any generic way to register dependency objects?

The issue is also I have a lot of classes that is not related to each other and in the dependency graph I would have to register these two.

Thanks!

You definitely should NOT create interfaces for your domain model. Interfaces should be created for things like repositories or services to be injected in each web api controller.

Edit You should create a repository interface for each aggregate root. What's an Aggregate Root?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM