Skip to content

Add TransactionManager.ImplicitDistributedTransactions #76469

@terrajobst

Description

@terrajobst

Background and motivation

Taken from #76376:

This adds a static, global TransactionManager.ImplicitDistributedTransactions flag, which must be explicitly turned on in order for distributed transactions to be supported.

The reasoning here, as advocated by @ajcvickers, is that back in .NET Framework many users were unintentionally causing escalation to a distributed transaction through improper use of TransactionScope, etc. This flag protects users interested in using TransactionScope but who do not want distributed transactions; this is important as distributed transactions shouldn't be used lightly and without careful consideration (dependency on MSDTC - an external component, considerable perf impact, portability to non-Windows platforms...).

Re the flag itself, TransactionManager already has global settings managing transactions. Re the name ImplicitDistributedTransactions, there's a possibility we'd introduce cross-platform distributed transactions into System.Transactions (#71769); if that happens, users will very explicitly create distributed transactions, and would not need to set this flag (hence "Implicit").

/cc @roji @ajcvickers

API Proposal

namespace System.Transactions;

public partial class TransactionManager
{
    [SupportedOSPlatform("windows")]
    public static bool ImplicitDistributedTransactions { get; set; }
}

API Usage

static void Main(string[] args)
{
    //...

    // Early on, the app is configured to enlist transactions into DTC:
    TransactionManager.ImplicitDistributedTransactions = true;

    //...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedarea-System.TransactionsblockingMarks issues that we want to fast track in order to unblock other important work

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions