所以我的服务中有一个方法,我将从控制器调用:
public void SendMessage(Message message) {
message.Property = "Random";
try {
// try some insert logic
}
catch (Exception) {
// if it fails undo some stuff
// return the errors
throw;
}
// if there are no errors on the return the operation was a success
// but how do I get the Service generated data?
}
编辑:
所以问题不在于让我的代码正常工作,而是我在使用服务层作为DAL和Presentation之间通信的“中间人”时使用存储库模式时遇到的问题
所以我有一个单独的程序集,称为DataLibrary
.
有我的DataLibrary
模型 ( Message
)、我的存储库和服务 ( MessageService
)
在我的 MVC 站点中,我通常会有一个具有 CRUD 功能的控制器。它看起来像这样:
public ActionResult Create(Message message) {
if(ModelState.IsValid) {
db.insert(message);
}
Return View(message);
}
但是通过使用存储库模式,以及用于通信的服务层,我得到了这个:
public ActionResult Create(MessageCreateModel message) {
if(ModelState.IsValid) {
MessageService.SendMessage(message.ToDTO());
}
Return View(message);
}
我如何知道手术成功或不成功以及出于什么原因?
如何在与上述同时从服务的业务逻辑中检索填充的数据?
以及如何在尽可能接近 MVC 设计模式/对可扩展性的关注点分离的同时实现上述两者?