Class MessagesSource<TBaseEvent>
- Namespace
- Silverback.Messaging.Messages
- Assembly
- Silverback.Core.dll
The default generic implementation of IMessagesSource. It contains some protected methods to add the internal events to a temporary collection exposed via the IMessagesSource implementation.
public abstract class MessagesSource<TBaseEvent> : IMessagesSource
Type Parameters
TBaseEventThe base type of the events being published.
- Inheritance
-
MessagesSource<TBaseEvent>
- Implements
- Derived
- Inherited Members
Remarks
This is the base class of the DomainEntity defined in Silverback.Core.Model.
Constructors
MessagesSource()
protected MessagesSource()
Methods
AddEvent(TBaseEvent)
Adds the specified event to the collection of events related to this object.
In the case of an entity model the event will be published when the entity is saved to the underlying database.
protected virtual void AddEvent(TBaseEvent @event)
Parameters
eventTBaseEventThe instance of
TBaseEventto be added.
AddEvent<TEvent>(bool)
Adds a new instance of TEvent to the collection of events related to
this object.
In the case of an entity model the event will be published when the entity is saved to the underlying database.
protected TEvent AddEvent<TEvent>(bool allowMultiple = true) where TEvent : TBaseEvent, new()
Parameters
allowMultipleboolif set to
falseonly one instance of the specified typeTEventwill be added.
Returns
- TEvent
The
TEventinstance that was added.
Type Parameters
TEventThe type of the event.
ClearMessages()
Called after the messages have been successfully published (and processed) to clear the messages collection.
public void ClearMessages()
GetMessages()
Gets the messages to be published.
public IEnumerable<object>? GetMessages()
Returns
- IEnumerable<object>
The message objects.
RemoveEvent(TBaseEvent)
Removes the specified event from the collection of events related to this object.
protected void RemoveEvent(TBaseEvent @event)
Parameters
eventTBaseEventThe
TBaseEventto be removed.
Remarks
This is used only to withdraw an event that wasn't published yet.