开发者

Keep Model and Repository in separate projects

I have a Visual Studio solution with multiple projects.

I am not 100% settled about the project structure and its benefits.

For example: I have a Project called DOMAIN. Here I have several folders like:

DOMAIN
|
|_Repository
  |__Implem开发者_如何学运维entations
  |____|__OrderRepository.cs
  |____|__CustomerRepository.cs
  |__Contracts
  |____|__IOrderRepository.cs
  |____|__ICustomerRepository.cs
  SessionManager.cs
  Model
  |__Customer.cs
  |__Order.cs

QUESTION: Should the Model be separated from the Repository in an extra project?

If yes, WHY?


If you strive for your application to be storage agnostic then yes. One way to do it is to have your model contain abstractions for your repositories, such as abstract classes or interfaces. Then you would have a separate project, which you could call something like data access layer (DAL), and it would hold a reference to your model project and implement the abstract repositories.

The benefits of this is a cleaner separation of responsibilities between your project (eg. your model project implements business logic and your DAL project knows the gory details about how to fetch data). Furthermore, this would allow you to implement two different DAL's, one targetting SQLServer and one targetting SqlLite for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜