Adding nesting options to DbConnectionScope.

I managed to squeeze in enough time to implement nesting options for the DbConnectionScope class.  My approach was to follow the nesting option pattern given by TransactionScope, so I added a DbConnectionScopeOptions enum with Required, RequiresNew and Suppress options.  The effect of these options is entirely contained within the DbConnectionScope constructor.

Required: If Current is null, makes this instance Current.  Otherwise, mark this instance as already Disposed.

RequiresNew: Same logic as original constructor — save prior value of Current to restore later and makes this instance Current.

Suppress: Saves prior value of Current to restore on Dispose and set Current to null.

I’ve also added an option to search through prior scopes for a connection.  If you pass in true, the current stack of connection scopes will be searched.  False means only search the current scope.

I’d like to thank Jian Zeng from the ADO.Net test team and Jim Carley from the System.Transaction team for taking the time to review the code and provide feedback prior to posting.


Comments (3)

  1. KjellSJ says:

    Thanks for the good work Alazela, just what the System.Transactions LTM clan needed. Now I can dump my own data session implementation.

  2. steveculshaw says:

    Any chance of a working example for a poor beginner like me  🙂


    Steve C.

  3. Jenser says:

    First, thanks for this greate piece of code…

    This code is safe in a ASP.NET context? See the link for background details for my question.