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!

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

5 Comments

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?
Definitly split up responsibility of objects. Check SRP (en.wikipedia.org/wiki/Single_responsibility_principle).
I aggree with Vladimir. You should split them up. Check my edit.
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.
Then i would suggest you to rethink your design and the single responsibility principle that Vladimir suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.