TechTalk Genome v4.2

Context.Push Method (IContext)

Sets the active Context in the calling thread, pushing the previously active (if any) context down in the context stack. The specified Context will be automatically disposed when unloaded by the disposer of the returned context stack cleaner object.

public static IDisposable Push(
   IContext context
);

Parameters

context
The Context that should become the active context.

Return Value

A new instance of a context stack cleaner object.

Remarks

The context stack cleaner object returned from this method pops context from the context stack when it is diposed. This combined with the using statement provides a safe and automatic context stack management. The caller of this method may choose to manage the context stack manually. In this case the returned context stack cleaner object is to be discarded.

A GenomeException is thrown if context is not the active Context in the calling thread when the cleaner is disposed. If context is popped by the caller, the returned context stack cleaner object must not be disposed. Similarly, any Context that is pushed on top of the context stack must be popped before disposing the returned context stack cleaner object.

The context stack cleaner also disposes context when unloading it from the context stack, thus freeing all resources held by it. This will release all locks and undo all uncommitted changes performed by context.

Example

using (Context.Push(ShortRunningTransactionContext.Create()))
{
    foreach (Employee e in dataDomain.Extent(typeof(Employee)) 
    {
        Console.WriteLine(e.Name);
    }
    // the context stack cleaner removes and disposes the context at the end of the using block
}
                

Requirements

Namespace: TechTalk.Genome

Assembly: TechTalk.Genome (in TechTalk.Genome.dll)

Version: 4.2.11.59

Editions: Professional, Evaluation, Express

See Also

Context Class | TechTalk.Genome Namespace | Context.Push Overload List | Pop | Current | CtxMgmtGuide.Chapter3