I'm having trouble finding an answer to this. Basically, right now I have these layers:
My repositories will return business objects. For example, GetCustomer will return Customer.
However, in my business layer, I also want to add logic that will use the repository to add/update/delete records, so I can reuse those methods in my MVC controllers. This doesn't work though, since I can't have my Data Access Layer reference my Business Layer and also have my Business Layer reference my Data Access Layer. (It creates a circular reference that is not allowed).
What do you guys think is the best solution? Should I put my Business Logic into it's own project?
So instead of:
Hello.Data
Hello.Business
I'll have:
Hello.Data
Hello.Business
Hello.BusinessLogic
Or am I thinking about this all wrong? Thanks!
Why would you separate business logic from business models? The logic should be in the models.
The business logic layer shouldn't have to reference anything, aside from maybe small common utility libraries. Basically, it should have no dependencies on infrastructure concerns (like application technologies, database technologies, etc.). It should contain just business logic.
All other layers should reference the business logic layer.
This doesn't work though, since I can't have my Data Access Layer reference my Business Layer and also have my Business Layer reference my Data Access Layer.
Correct! The mistake in this design is that the business logic layer references the data access layer at all . It shouldn't.
It should , however, contain interfaces for data access (and other infrastructure concerns) which are implemented by the data access layer. The business logic layer only needs to know about the interfaces, it doesn't know or care what implements those interfaces.
A dependency injection container would then be used to connect implementations to interfaces.
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.