Giter Site home page Giter Site logo

servicetmpl1's Issues

我想咨询或探讨一个关于事务问题, 请指教

我拜读你写的文章: 清晰架构(Clean Architecture)的Go微服务: 事物管理, 思路很好, 不过我还有一个问题没思考明白:

不知道你有没有遇到一个事务跨几个DataService的场景?

假如 我定义了两个DataService: OrderDataInterface, ProductDataInterface, 分别处理订单数据与商品数据, 继续, 现在我定义了一个UserCase: OrderUseCase, 它依赖OrderDataInterfaceProductDataInterface来进行下单操作: 新建一个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, 想与你实时交流更方便. 如有打扰请见谅.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.