Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以定义自己的环境类?
例如,TransactionScope 类使任何实现 IEnlistmentNotification(我认为)的对象都可以使用它,而无需任何代码显式地将一个对象的引用传递给另一个对象。
我不确定我是否需要使用它,但了解它是如何工作的会很有趣(即我如何在我自己的代码中实现这样的功能)。这是我们可以构建到我们自己的类中的东西,还是在较低级别开发的东西以允许 TransactionScope 做一些超出“常规开发人员”级别可用的东西?
写作new TransactionScope()只是设置静态Transaction.Current属性。
new TransactionScope()
Transaction.Current
其他类可以检查该属性是否不为空,并在事务中登记自己。
没有魔法。