Having watched samples from Rob Conery's Kona application, I see that he is using two things with IoC - ISession, where he has data layer code and Services, where he has some additional business logic that we need to perform when manipulating data in datastore. For instance, we might not just add a record to the DB but also change properties of another record, increase some counts, take something back, etc. We need to put that additional code somewehere and he puts it in those services.
For instance, he has a CustomerService that manipulates Customers. This requires us to send ISession instance to the CustomerService, so that the CustomerService can use it to access the datastore.
现在,另一种方法是将额外的代码放入客户类本身,并将isession(或iRepository,无论我们使用什么术语)发送到该类。没有任何服务。通常,客户、订单、产品等类都是模型类,因此会产生大/重的模型类。
我的问题是,哪种解决方案更好?到目前为止,我不需要这样做,因为我在控制器中拥有大部分代码,但是现在随着应用程序的增长,我需要对此作出决定并清理控制器。
Currently I have:
- fat controllers with business logic in it,
- very atomic repositories,
- very clean models and viewmodels.
我应该搬到:
- slim controllers,
- repositories with more code,
- models with business logic code (specifically should my model classes contain methods like Add(), Remove(), for instance Customer.Remove()??)
或
- slim controllers,
- atomic repositories,
- still clean models,
- services (to encapsulate everything else that does not go into any of the previous).