Class EventSourcingDomainEntity<TKey, TDomainEvent>
The base class for the domain entities that are persisted in the event store.
Inherited Members
Namespace: Silverback.Domain
Assembly: Silverback.EventSourcing.dll
Syntax
public abstract class EventSourcingDomainEntity<TKey, TDomainEvent> : MessagesSource<TDomainEvent>, IMessagesSource, IEventSourcingDomainEntity<TKey>, IEventSourcingDomainEntity
Type Parameters
Name | Description |
---|---|
TKey | The type of the entity key. |
TDomainEvent | The base type of the domain events. |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
Constructors
| Improve this doc View sourceEventSourcingDomainEntity()
Initializes a new instance of the EventSourcingDomainEntity<TKey, TDomainEvent> class.
Declaration
protected EventSourcingDomainEntity()
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
EventSourcingDomainEntity(IReadOnlyCollection<IEntityEvent>)
Initializes a new instance of the EventSourcingDomainEntity<TKey, TDomainEvent> class from the stored events.
Declaration
protected EventSourcingDomainEntity(IReadOnlyCollection<IEntityEvent> events)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCollection<IEntityEvent> | events | The stored events to be re-applied to rebuild the entity state. |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
Properties
| Improve this doc View sourceDomainEvents
Gets the domain events that have been added but not yet published.
Declaration
[NotMapped]
public IEnumerable<TDomainEvent> DomainEvents { get; }
Property Value
Type | Description |
---|---|
IEnumerable<TDomainEvent> |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
Events
Gets the events that have been applied to build the current state.
Declaration
[NotMapped]
public IEnumerable<IEntityEvent> Events { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IEntityEvent> |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
Id
Gets the entity identifier.
Declaration
public TKey Id { get; protected set; }
Property Value
Type | Description |
---|---|
TKey |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
Methods
| Improve this doc View sourceAddAndApplyEvent(IEntityEvent)
Adds the specified event and applies it to update the entity state.
Declaration
protected virtual IEntityEvent AddAndApplyEvent(IEntityEvent entityEvent)
Parameters
Type | Name | Description |
---|---|---|
IEntityEvent | entityEvent | The event to be added. |
Returns
Type | Description |
---|---|
IEntityEvent | The IEntityEvent that was added and applied. |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
GetNewEvents()
Returns the new events that have to be persisted.
Declaration
public IEnumerable<IEntityEvent> GetNewEvents()
Returns
Type | Description |
---|---|
IEnumerable<IEntityEvent> | The new events to be persisted. |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.
GetVersion()
Returns the version of the entity. In the default implementation this is a sequence that is increment every time a new event is applied.
Declaration
public int GetVersion()
Returns
Type | Description |
---|---|
int | The entity version. |
Remarks
It's not mandatory to use this base class as long as long as the domain entities implement the IEventSourcingDomainEntity<TKey> interface.