TechTalk Genome v4.2

Context Class

Encapsulates an access session to all DataDomains.

For a list of all members of this type, see Context Members.

System.Object
   Context

public class Context : IContext, IDisposable

Remarks

The Context class encapsulates a data access session to all DataDomains in the calling AppDomain. All modifications to persistent data are routed trough the active Context that governs the operation.

New instances of the Context class can be created by using one of the predefined context factory classes: LocalContext, ShortRunningTransactionContext and ReadOnlyContext.

These classes are used to create new preconfigured instances of the Context class that allows the caller to declare different access strategies to be used when retrieving or updating objects in the DataDomains. The following aspects can be configured:

AspectDescription
Cache resource management Determines the size and the resource management strategy of the cache maintained by the created context. The current implementation supports unmanaged and last-recently-used resource management.
Cache invalidation Determines how objects are invalidated from the cache of the created context. The current implementation supports manual, and timed invalidation strategies.
Transaction behaviour Determines how changed objects are updated into the DataDomain. The current implementation supports long running (LocalContext), short running (ShortRunningTransactionContext) and read-only (ReadOnlyContext) transaction models.

When a persistent object is accessed by the application, a stateless proxy to the object is returned only. The proxy serves as a handle to the state of the object that is being kept in one or more Contexts. When the caller calls methods or accesses properties of a persistent object, the active Context is used to retrieve state data, thus allowing different blocks of the application to be isolated in how they see the persistent state. The active Context is determined using different strategies, based on the proxy type.

In the current implementation each Thread maintains its own stack of contexts. The Context on the top of the stack is the active context in that thread. Every program block in the executing application can define alternative data access strategies by creating its custom configured context and setting it as the active context of its thread by calling the Push method. After the program block has executed the context is unloaded from the executing thread using the Pop method, thus restoring the context that was active before the program block would have been called. Alternatively a program block can decide to use the active context provided by its caller thus making the program block configurable in terms of data access strategies.

Proxies returned by Genome are context independent, that is they do not have any Context preference. Whenever data is accessed on an unbound proxy, the context stack of the calling thread is investigated to acquire the active context as returned by Current. Thus the Context used by unbound proxies solely depends on the previous Push method calls in the same thread. Since context independent proxies are not bound to any context, they are valid even if the active Context in the calling thread is discarded - although the proxy might access different state of the same object when applied in a different Context.

Context-bound proxies are made explicitly bound to their active Context using the Pin<S> method. Whenever data is accessed on a context-bound proxy the active Context in the calling thread is ignored and the referred Context is used. Whenever a method call is made on a context-bound proxy, the referred Context is made active in the calling thread temporarily for the time of the call.

As opposed to unbound proxies, context bound proxies become invalid if their active Context is discarded. If the caller attempts to access object state or call methods on a bound proxy if its active Context has been already disposed, Genome throws a GenomeException. In this case, the caller can use Unpin<S> to regain a context-free proxy to the object, or Pin<S> to gain a proxy bound to a valid context for the same object.

Requirements

Namespace: TechTalk.Genome

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

Version: 4.2.11.59

Editions: Professional, Evaluation, Express

Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Orcale 9i Release 2, Oracle 10g Release 2

See Also

Context Members | TechTalk.Genome Namespace | LocalContext | ShortRunningTransactionContext | ReadOnlyContext | CtxMgmtGuide.Foreword