Frage

Is it possible to define your own ambient classes?

For example, the TransactionScope class makes itself available to any object which implements IEnlistmentNotification (I think), without any code to explicitly pass a reference of one object to the other.

I'm not sure if I'd ever need to use this, but it would be interesting to understand how it worked (i.e. how I could implement such functionality in my own code). Is this something we can build into our own classes, or was something developed at a lower level to allow TransactionScope to do something beyond what's available at the "regular developer" level?

War es hilfreich?

Lösung

Writing new TransactionScope() just sets the static Transaction.Current property.

Other classes can check whether this property is not null and enlist themselves in the transaction.

There is no magic involved.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top