[英]ServiceStack Application Structure
I have recently started looking at ServiceStack
and how we could implement it in our architecture. 我最近开始研究
ServiceStack
以及如何在体系结构中实现它。 We have been using ASP.NET MVC 3/4 with the Service/Repository/UnitOfWork pattern. 我们一直在使用带有Service / Repository / UnitOfWork模式的ASP.NET MVC 3/4。
I am looking for resources of how to integrate ServiceStack into the mix. 我正在寻找有关如何将ServiceStack集成到混合中的资源。
What we usually have looks something like this: 我们通常所拥有的看起来像这样:
MVC Controller/Action
--> Service
--> Repository
--> Entity Framework
MVC Controller/Action
-> Service
-> Repository
-> Entity Framework
I want to re-use the domain model we have and expose it through ServiceStack, so do I just have the operation's on the services return the domain models? 我想重新使用现有的域模型并通过ServiceStack公开它,那么我是否只需对服务进行操作即可返回域模型?
EG 例如
// Request DTO
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
}
// Response DTO
public class CustomerResponse
{
public List<Customer> Customers { get; set; }
}
// Customer Service
public class CustomerService : IService
{
public object Any(BrowseCustomers request)
{
var customers = new List<Customer>() {
new Customer {
FirstName = "Joe",
LastName = "Bob",
...
},
new Customer {
FirstName = "Jill",
LastName = "Bob",
...
}
};
return customers.Where(x => x.FirstName.ToLower().StartsWith(request.FirstName.ToLower()));
}
}
Edit 编辑
I guess what I am asking is; 我想我要问的是; Should I return Domain Objects in the Response DTO's from the ServiceStack Services?
我是否应该从ServiceStack服务返回响应DTO中的域对象? Or should I not return domain objects at all, rather make entity DTO's instead?
还是我根本不应该返回域对象,而是让实体DTO代替?
For a fairly comprehensive write-up on Service Stack application architecture, see Demis' answer here . 有关服务栈的应用程序架构相当全面的写了,见杰米斯答案在这里 。
Long story short, as long as your Domain objects are POCOs (Plain Old CLR Objects - meaning no methods or inheritance going on), then you should be fine. 长话短说,只要您的Domain对象是POCO(普通的旧CLR对象-意味着不会进行任何方法或继承),那么您就可以了。
The important point is that your Request/Response DTOs are logical for the operations you want to expose with your services. 重要的是,您的请求/响应DTO对于要随服务公开的操作是合乎逻辑的。 Don't use a Domain model for a Request DTO because it's convenient, do it because it's the best choice.
不要将域模型用于请求DTO,因为它很方便,请这样做,因为它是最佳选择。 Having your Response DTOs contain Domain models is quite common, though.
但是,让您的Response DTO包含Domain模型是很常见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.