简体   繁体   中英

How to implement Unit Of Work pattern with Dapper in the multi thread environment?

I am using the below Unit of work implementation in my application. URL reference : How to implement Unit Of Work pattern with Dapper?

This is working fine with single thread application. But if i want to use same code for multi thread application, then its creating a problem.

Example: I am creating unit of work object with AddScoped services.AddScoped<IUnitOfWork, UnitOfWork>();

Old Transaction object will be replaced by new transaction object, when more than one thread calling unit of work Begin() method in single web request.

AddScoped 为每个请求创建一个实例,因此,如果您需要在单个请求中执行多个线程,其中每个线程都运行到一个事务中,请使用此工作单元代码,我认为您需要更新您的工作单元代码以管理每个线程的一个连接

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM