Configuración
El patrón de opciones es una técnica común en aplicaciones .NET que permite centralizar la configuración en un solo lugar, facilitando la gestión y validación de las opciones de configuración. En CodeDesignPlus.Net.Event.Sourcing
, utilizamos este patrón para ofrecer opciones de configuración estructuradas y fácilmente accesibles.
EventSourcingOptions
La clase EventSourcingOptions proporciona opciones para configurar el event sourcing en la aplicación. A continuación, se listan las opciones de configuración y sus propiedades.
namespace CodeDesignPlus.Net.Event.Sourcing.Abstractions.Options;
/// <summary>/// Options for configuring Event Sourcing./// </summary>public class EventSourcingOptions{ /// <summary> /// Name of the section used in the appsettings. /// </summary> public static readonly string Section = "EventSourcing";
/// <summary> /// Gets or sets the main name for the aggregate. /// This is used as the central part of the naming pattern for aggregates in the event store. /// </summary> public string MainName { get; set; } = "aggregate";
/// <summary> /// Gets or sets the suffix used to denote snapshots in the naming pattern for aggregates in the event store. /// When an aggregate's state is persisted as a snapshot, this suffix is appended to the aggregate's name. /// </summary> public string SnapshotSuffix { get; set; } = "snapshot";
/// <summary> /// Gets or sets the frequency at which snapshots are taken for Event Sourcing. /// </summary> [Range(1, 500)] public int FrequencySnapshot { get; set; } = 20;}
Propiedades
- Section: Nombre de la sección utilizada en el appsettings.
public static readonly string Section = "EventSourcing";
- SnapshotSuffix: Sufijo utilizado para denotar snapshots en el patrón de nombres para los agregados en el almacén de eventos. Cuando el estado de un agregado se persiste como un snapshot, este sufijo se agrega al nombre del agregado.
public string SnapshotSuffix { get; set; } = "snapshot";
- FrequencySnapshot: Frecuencia con la que se toman snapshots para el event sourcing.
[Range(1, 500)]public int FrequencySnapshot { get; set; } = 20;
Ejemplo de configuración
Para configurar las opciones de EventSourcing, agregue la siguiente sección a su archivo appsettings.json
.
{ "EventSourcing": { "SnapshotSuffix": "snapshot", "FrequencySnapshot": 20 }}