コード例 #1
0
        public void ApplyTransactionSupport(IChain chain, IContainer container)
        {
            var shouldFlushOutgoingMessages = chain.ShouldFlushOutgoingMessages();


            var frame = new DbTransactionFrame <NpgsqlTransaction, NpgsqlConnection>
            {
                ShouldFlushOutgoingMessages = shouldFlushOutgoingMessages
            };

            chain.Middleware.Add(frame);
        }
コード例 #2
0
        public void ApplyTransactionSupport(IChain chain, IContainer container)
        {
            var dbType = DetermineDbContextType(chain, container);

            chain.Middleware.Insert(0, new EnrollDbContextInTransaction(dbType));


            var saveChangesAsync = dbType.GetMethod(nameof(DbContext.SaveChangesAsync), new Type[] { typeof(CancellationToken) });
            var @call            = new MethodCall(dbType, saveChangesAsync);

            @call.CommentText = "Added by EF Core Transaction Middleware";

            chain.Postprocessors.Add(@call);

            if (chain.ShouldFlushOutgoingMessages())
            {
                chain.Postprocessors.Add(MethodCall.For <IMessageContext>(x => x.SendAllQueuedOutgoingMessages()));
            }
        }