jfeng45 / servicetmpl1 Goto Github PK
View Code? Open in Web Editor NEWA self-evolved Microservice framework for Go and gRPC--an upgrade version for "servicetmpl"
License: MIT License
A self-evolved Microservice framework for Go and gRPC--an upgrade version for "servicetmpl"
License: MIT License
我拜读你写的文章: 清晰架构(Clean Architecture)的Go微服务: 事物管理, 思路很好, 不过我还有一个问题没思考明白:
不知道你有没有遇到一个事务跨几个DataService的场景?
假如 我定义了两个DataService: OrderDataInterface
, ProductDataInterface
, 分别处理订单数据与商品数据, 继续, 现在我定义了一个UserCase: OrderUseCase
, 它依赖OrderDataInterface
和ProductDataInterface
来进行下单操作: 新建一个Order并将Product库存减一, 这两个操作我想做到一个事务里.
我看到此仓库的代码里只能对其中一个DataService开启事务:
import (
"github.com/jfeng45/servicetmpl1/applicationservice/dataservice"
"github.com/jfeng45/servicetmpl1/domain/model"
)
// RegistrationTxUseCase implements RegistrationTxUseCaseInterface.
// It has UserDataInterface, which can be used to access persistence layer
type RegistrationTxUseCase struct {
UserDataInterface dataservice.UserDataInterface
}
// The use case of ModifyAndUnregister with transaction
func (rtuc *RegistrationTxUseCase) ModifyAndUnregisterWithTx(user *model.User) error {
udi := rtuc.UserDataInterface
return udi.EnableTx(func() error {
// wrap the business function inside the TxEnd function
return ModifyAndUnregister(udi, user)
})
}
我想让一个事务跨几个DataService, 请问这个情况下我应该如何构建代码?
不知道你还用qq吗? 我的qq是 1019654929, 想与你实时交流更方便. 如有打扰请见谅.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.