用于批处理操作的自动查询 CRUD
Autoquery CRUD for batch operations
是否有任何实践使用 ServiceStack AutoQuery Crud
到 post 多个 CreateDb<T>
请求在单个事务中插入多行(自动批处理请求?)?
更新:我尝试使用@mythz 解决方案,但用于处理 ICreateDb 类型的批处理请求的自定义服务导致异常 ResolutionException
:
"Required dependency of type aproject.core.ServiceInterface.Services.ProjectContractsService could not be resolved."
Funq.ResolutionException: Required dependency of type aproject.core.ServiceInterface.Services.ProjectContractsService could not be resolved. at ServiceStack.Host.ContainerResolveCache.CreateInstance(IResolver resolver, Type type, Boolean tryResolve) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ContainerResolveCache.cs:line 60 at ServiceStack.Host.ContainerResolveCache.CreateInstance(IResolver resolver, Type type) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ContainerResolveCache.cs:line 34 at ServiceStack.Host.ServiceController.<>c__DisplayClass41_0.<RegisterServiceExecutor>g__HandlerFn|0(IRequest req, Object dto) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ServiceController.cs:line 437 at ServiceStack.Host.ServiceController.ExecuteAsync(Object requestDto, IRequest req) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ServiceController.cs:line 674 at ServiceStack.Host.Handlers.GenericHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\Handlers\GenericHandler.cs:line 62
Autoquery 已正确注册,但我发现用于打包条目的 ICreateDb DTO 已注册多次:
DEBUG: Registering OneWay service 'ContractsService' with request 'CreateContractEstimate[]' DEBUG: Registering Reply service '__AutoQueryServices' with request 'CreateContractEstimate'
我刚刚实现了对所有 CRUD 操作的自动实现批处理实现的支持,默认情况下将在数据库事务中执行所有自动查询 CRUD 请求。
默认情况下,它将为所有 CRUD 操作生成 AutoBatch 实现,并且可以通过更改更改为仅为特定 CRUD 操作生成实现:
Plugins.Add(new AutoQueryFeature {
GenerateAutoBatchImplementationsFor = new() { AutoCrudOperation.Create }
});
它也不会为自定义 AutoBatch 实现生成实现,例如您可以添加一个自定义实现来执行生成的实现将完成的操作并使用相同的数据库连接和事务执行:
public class CustomAutoQueryServices : Service
{
public IAutoQueryDb AutoQuery { get; set; }
public object Any(CreateItem[] requests)
{
using var db = AutoQuery.GetDb<Item>(Request);
using var dbTrans = db.OpenTransaction();
var results = new List<object>();
foreach (var request in requests)
{
var response = await AutoQuery.CreateAsync(request, Request, db);
results.Add(response);
}
dbTrans.Commit();
return results;
}
}
和AutoQuery Services are just normal ServiceStack Services you can re-use the existing Service Client support for Auto Batched Requests,例如:
var client = new JsonServiceClient(BaseUrl);
var response = client.SendAll(new CreateItem[] { ... });
此功能从 v5.11.1 开始提供,现在 available on MyGet。
是否有任何实践使用 ServiceStack AutoQuery Crud
到 post 多个 CreateDb<T>
请求在单个事务中插入多行(自动批处理请求?)?
更新:我尝试使用@mythz 解决方案,但用于处理 ICreateDb 类型的批处理请求的自定义服务导致异常 ResolutionException
:
"Required dependency of type aproject.core.ServiceInterface.Services.ProjectContractsService could not be resolved."
Funq.ResolutionException: Required dependency of type aproject.core.ServiceInterface.Services.ProjectContractsService could not be resolved. at ServiceStack.Host.ContainerResolveCache.CreateInstance(IResolver resolver, Type type, Boolean tryResolve) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ContainerResolveCache.cs:line 60 at ServiceStack.Host.ContainerResolveCache.CreateInstance(IResolver resolver, Type type) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ContainerResolveCache.cs:line 34 at ServiceStack.Host.ServiceController.<>c__DisplayClass41_0.<RegisterServiceExecutor>g__HandlerFn|0(IRequest req, Object dto) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ServiceController.cs:line 437 at ServiceStack.Host.ServiceController.ExecuteAsync(Object requestDto, IRequest req) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\ServiceController.cs:line 674 at ServiceStack.Host.Handlers.GenericHandler.ProcessRequestAsync(IRequest httpReq, IResponse httpRes, String operationName) in C:\BuildAgent\work81147c480f4a2f\src\ServiceStack\Host\Handlers\GenericHandler.cs:line 62
Autoquery 已正确注册,但我发现用于打包条目的 ICreateDb DTO 已注册多次:
DEBUG: Registering OneWay service 'ContractsService' with request 'CreateContractEstimate[]' DEBUG: Registering Reply service '__AutoQueryServices' with request 'CreateContractEstimate'
我刚刚实现了对所有 CRUD 操作的自动实现批处理实现的支持,默认情况下将在数据库事务中执行所有自动查询 CRUD 请求。
默认情况下,它将为所有 CRUD 操作生成 AutoBatch 实现,并且可以通过更改更改为仅为特定 CRUD 操作生成实现:
Plugins.Add(new AutoQueryFeature {
GenerateAutoBatchImplementationsFor = new() { AutoCrudOperation.Create }
});
它也不会为自定义 AutoBatch 实现生成实现,例如您可以添加一个自定义实现来执行生成的实现将完成的操作并使用相同的数据库连接和事务执行:
public class CustomAutoQueryServices : Service
{
public IAutoQueryDb AutoQuery { get; set; }
public object Any(CreateItem[] requests)
{
using var db = AutoQuery.GetDb<Item>(Request);
using var dbTrans = db.OpenTransaction();
var results = new List<object>();
foreach (var request in requests)
{
var response = await AutoQuery.CreateAsync(request, Request, db);
results.Add(response);
}
dbTrans.Commit();
return results;
}
}
和AutoQuery Services are just normal ServiceStack Services you can re-use the existing Service Client support for Auto Batched Requests,例如:
var client = new JsonServiceClient(BaseUrl);
var response = client.SendAll(new CreateItem[] { ... });
此功能从 v5.11.1 开始提供,现在 available on MyGet。