Description
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;
//...
}