所以我在我的服务的方法,我会从一个控制器调用:MVC存储库模式与服务 - 如何获得DAL错误?
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和演示之间
所以我有一个单独的程序集叫做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设计模式/关注可扩展性的前提下,如何实现上述两者?
为了澄清,服务层,回购和DTO包装在一个单独的程序集内。 – Smithy 2013-04-29 15:08:24