Coder Social home page Coder Social logo

luoyunchong / dotnetcore.cap.provider Goto Github PK

View Code? Open in Web Editor NEW
6.0 3.0 4.0 43 KB

为DotNetCore.CAP 增加FreeSql中的统一事务提交,基于如下类库

Home Page: https://github.com/dotnetcore/CAP

C# 100.00%
cap freesql orm cap-freesql dotnetcore

dotnetcore.cap.provider's Introduction

Hi 👋, I'm IGeekFan(天上月) ,我是一名 C#/ASP.NET Core/JavaScript开发者

🍳 推荐项目

📈 Github Statistics

🏆 欢迎微信搜索:dotNET搬砖队

dotnetcore.cap.provider's People

Contributors

luoyunchong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dotnetcore.cap.provider's Issues

沙发,关于 Cap 接入问题建议

大哥好,你现在这样封装肯定可以。

问题初衷:

如何在外部控制事务提交?

因为提交事务的操作中可能还有其他操作,不是简单 tran.Commit() 就完事。

如果把事务提交权交给 Cap,整个事务就终断。

伪代码如下:

using (var uow = ....())
{
    _capPublisher.Transaction.Value.Begin(uow.Transaction);
    //...
    uow.Commit(); // 这样提交 _capPublisher.Flush 没有被执行
}
using (var uow = ....())
{
    _capPublisher.Transaction.Value.Begin(uow.Transaction);
    //...
    capPublisher.Commit(); // 这样提交 uow.Commit 内部其他逻辑没有被执行
}

建议:开放 Flush 方法给外部使用

Cap 作者否决了我的意图,不给支持,其实很简单的一个改动。如果每个数据库自己 copy 代码来改比较复杂,建议代码如下:

public static class CapUnitOfWorkExtenssions
{
    public static void SetCapPublisher(this IUnitOfWork fsql, ICapPublisher capPublisher)
    {
        capPublisher.Transaction.Value.Begin(uow.GetOrBeginTransaction());
    }
    public static void Flush(this ICapPublisher capPublisher)
    {
        capPublisher?.GetType().GetMethod("Flush", BindingFlags.Instance | BindingFlags.NonPublic)
            .Invoke(capPublisher, null);
    }
}

using (var uow = fsql.CreateUnitOfWork())
{
    uow.SetCapPublisher(_capPublisher);
    //...
    uow.Commit();
    capPublisher.Flush(); //执行 mq 推送
}

这样一来就不用为每个数据库去做这个了

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.