Class ProjectionVersionAttribute
- Namespace
- Excalibur.EventSourcing
- Assembly
- Excalibur.EventSourcing.Abstractions.dll
Declares the generation of a projection's read model, so that changing how the model is shaped or folded sends it to a new destination instead of mutating the one already serving reads.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct, Inherited = false, AllowMultiple = false)]
public sealed class ProjectionVersionAttribute : Attribute
- Inheritance
-
ProjectionVersionAttribute
- Inherited Members
Examples
// Generation 2 folds into its own destination; generation 1 keeps serving reads meanwhile.
[ProjectionVersion(2)]
public sealed class OrderSummary
{
public string OrderId { get; set; } = string.Empty;
public string CustomerName { get; set; } = string.Empty; // renamed from Customer in generation 2
}
Remarks
What this exists to prevent. Renaming a property or changing a fold rule alters what the stored documents mean while leaving the destination -- the index, container, collection or table -- addressed by exactly the same name. The old and new shapes then interleave in one destination, and nothing reports it: a search provider may reject the write on a mapping conflict, but the remaining providers accept it and the read model is silently part stale. Declaring a new generation makes the destination name different, so the new generation folds from zero into its own destination while the previous one keeps its cursor and keeps serving reads until you cut over.
Generation 1 is the unversioned destination, byte for byte. A projection with no attribute is
generation 1, and so is one declaring 1 explicitly: both resolve to the destination name they
resolve to today. A version segment appears only from generation 2 onward. That is what lets an
existing read model adopt this attribute without re-folding -- label the current shape
[ProjectionVersion(1)] and nothing moves; the first bump to 2 is the first new
destination.
It is read once, when the store is constructed. The value is a compile-time constant of the read-model type rather than a configuration setting, so it cannot change under a running store whose destination was already resolved, and a tool that plans a cutover can read it from the type without building a container.
Where the segment lands is the provider's choice, not a shared format. Each provider places it using the separator its own identifiers allow, because a name that is legal for a search index is not always a legal SQL identifier.
Constructors
ProjectionVersionAttribute(int)
Initializes a new instance of the ProjectionVersionAttribute class.
public ProjectionVersionAttribute(int version)
Parameters
versionintThe generation of the read model, from 1. Generation 1 resolves to the same destination name as a projection that declares no generation at all.
Exceptions
- ArgumentOutOfRangeException
Thrown when
versionis less than 1.
Properties
Version
Gets the declared generation of the read model.
public int Version { get; }
Property Value
- int
The generation number, from 1.