In order to use LightSpeed effectively it is useful to a have a reasonable understanding of the framework’s underlying architecture. The following sections provide a high-level discussion of the architecture of LightSpeed and also describe some of the foundational design patterns underpinning its design.
LightSpeedContext Class
A central object within the framework is the LightSpeedContext class. The class is primarily a central registry for shared configuration and services relating to a single data context. The following class diagram provides a visual view of LightSpeedContext and some of its key properties.
LightSpeedContext Class Diagram
The IUnitOfWork Interface
A central concept in LightSpeed is that of unit of work (see patterns discussion below). LightSpeed defines a unit of work through the IUnitOfWork interface and provides the default implementation: UnitOfWork. Instances of IUnitOfWork are created by calling the LightSpeedContext.CreateUnitOfWork method.
IUnitOfWork Class Diagram
The Entity Framework
LightSpeed also includes a base Entity framework that assists in the creation of effective .NET domain models. Central to the framework is of course the Layer Supertype Entity<TId> base class. This class handles, among other things, state tracking and validation and also implements the key databinding interfaces: IEditableObject, INotifyPropertyChanged and IDataErrorInfo. Other key classes include EntityCollection and EntityHolder which are used to declare one-to-many and many-to-one or one-to-one associations respectively. The class diagram below shows the key classes making up the LightSpeed entity framework.
Entity Framework Class Diagram
Design Patterns in LightSpeed
LightSpeed employs many common and well-known best-practice design patterns.
Unit of Work
Perhaps the pattern most central to LightSpeed is the Unit of Work pattern:
Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
Roughly speaking a unit of work is just a logical collection of pending database operations corresponding to a business transaction. The process of updating a database with the changes in a unit of work is often called a “Flush”. In LightSpeed, the implementation of this pattern provides a number of benefits including:
- Entity state changes are tracked automatically.
- Connection handling is an efficient, acquire-late, release early strategy.
- LightSpeed employs very efficient SQL batching strategies reducing database round-trips.
- Each unit of work uses an internal Identity Map which acts as a unit of work local entity cache. The IUnitOfWork adheres to IEnumerable<Entity> which allows developers to iterate over the associated entities in a unit of work should they need to.
Unit of Work Mechanics provides more detailed information about how LightSpeed implements the Unit of Work pattern.
Other Patterns
Other design patterns at work in or facilitated by LightSpeed include: