using System;
using System.Transactions;
public class FooUseCase
{
// UseCaseクラスに存在する登録メソッドの例
public void CreateFoo()
// usingが付いた変数tranはスコープを抜ける際にDisposeメソッドが呼ばれる
// TransactionScopeAsyncFlowOption.Enabledを指定せずにnewしてからDisposeするまでの間にスレッドが変わると↓の例外がthrowされる
// System.InvalidOperationException: A TransactionScope must be disposed on the same thread that it was created.
using var tran = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
// RepositoryでDBへの登録処理
tran.Complete();
}