1

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!

user3514987
  • 210
  • 3
  • 9

1 Answers1

2

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?

Community
  • 1
  • 1
Vagelis Ouranos
  • 482
  • 3
  • 14
  • I did not create an interface for my domain model. I created ICustomerRepository interface. In the interface I've added CRUD signatures that is used in the class. But should I create all my entites in this repository or should I split it up? Like ICustomerRepository, IProductRepoistory, IPurchaseRespositry etc? – user3514987 Aug 05 '15 at 07:51
  • 1
    Definitly split up responsibility of objects. Check SRP (https://en.wikipedia.org/wiki/Single_responsibility_principle). – Vladimir Kocjancic Aug 05 '15 at 07:53
  • I aggree with Vladimir. You should split them up. Check my edit. – Vagelis Ouranos Aug 05 '15 at 08:00
  • Okay thank you.. But what about my other question? What about other objects that is depending on other objects ? Such as for example if I have a Settings class that is used in one repoistory. – user3514987 Aug 05 '15 at 08:17
  • Then i would suggest you to rethink your design and the single responsibility principle that Vladimir suggested. – Vagelis Ouranos Aug 05 '15 at 08:20