C# 自动生成服务、其DTO和DAO
我正在使用ServiceStack将我的胖客户端连接到我们的API服务器,我非常喜欢它。然而,我发现必须为每个请求编写三个类(Foo、FooResponse和FooService)有些麻烦 在我的项目中,我有很多DAO接口,看起来像这样:C# 自动生成服务、其DTO和DAO,c#,automation,
servicestack,C#,Automation,
servicestack,我正在使用ServiceStack将我的胖客户端连接到我们的API服务器,我非常喜欢它。然而,我发现必须为每个请求编写三个类(Foo、FooResponse和FooService)有些麻烦 在我的项目中,我有很多DAO接口,看起来像这样: public interface ICustomerDao { public IList<Customer> FindCustomers(long regionId, string keyword); } public interface
public interface ICustomerDao {
public IList<Customer> FindCustomers(long regionId, string keyword);
}
public interface ICustomerDao {
[AutoApi("Loads customers for the given region whose names match the keyword")]
[AutoRoute("/search/customer/{regionId}/{keyword}"]
public IList<Customer> FindCustomers(long regionId, string keyword);
}
public class SomeBusinessLogic {
[AutoService(typeof(ICustomerDao))]
public IList<Customer> FindCustomers(long regionId, string keyword) {
// lots of business logic here
}
}
公共接口ICCustomerDAO{
公共IList FindCustomers(长regionId,字符串关键字);
}
我想这样说:
public interface ICustomerDao {
public IList<Customer> FindCustomers(long regionId, string keyword);
}
public interface ICustomerDao {
[AutoApi("Loads customers for the given region whose names match the keyword")]
[AutoRoute("/search/customer/{regionId}/{keyword}"]
public IList<Customer> FindCustomers(long regionId, string keyword);
}
public class SomeBusinessLogic {
[AutoService(typeof(ICustomerDao))]
public IList<Customer> FindCustomers(long regionId, string keyword) {
// lots of business logic here
}
}
公共接口ICCustomerDAO{
[AutoApi(“加载名称与关键字匹配的给定区域的客户”)]
[自动路由(“/search/customer/{regionId}/{keyword}”]
公共IList FindCustomers(长regionId,字符串关键字);
}
公共类业务逻辑{
[自动服务(类型化(ICCustomerDAO))]
公共IList FindCustomers(长regionId,字符串关键字){
//这里有很多商业逻辑
}
}
然后,我希望为我自动生成以下类:
:一个ServiceStack DTO请求FindCustomers
:响应查找客户响应
:一种服务,它接受FindCustomers数据,然后调用FindCustomersService
,并将其返回值包装在SomeBusinessLogic.FindCustomers(req.RegionId,req.Keyword)
FindCustomersResponse
:通过自动生成方法实现ApiServiceCustomerDao
,这些方法构造FooRequest并联系相应的服务,然后接收FooResponse并自动解包iccustomerdao
QueryResponse
响应类型,因此不会动态生成DTO,并且由于代码优先请求DTO,客户端,例如:
我不知道服务堆栈,但您描述的是泛型。如果它们不起作用,因为您使用的工具无法正确序列化请求(如果您还没有准备好放弃这些限制),您可能可以编写一个t4模板,根据某些属性生成有问题的类(例如,您在上文中的建议)AutoQuery听起来不错,但我可以使用它来执行自定义业务逻辑代码,还是仅限于SQL查询和集合查询?@Bugmaster它主要用于创建数据驱动服务,但仍然允许。但是如果您仍然需要更多的控制,您可以查看AutoQuery创建和注册动态se的方法服务。