Class EventSerializer
- Namespace
- Cratis.Chronicle.Events
- Assembly
- Cratis.Chronicle.dll
Represents an implementation of IEventSerializer.
[Scoped]
public class EventSerializer : IEventSerializer
- Inheritance
-
EventSerializer
- Implements
- Inherited Members
- Extension Methods
Remarks
The serializer holds the IEventTypes registry of the event store for the current dependency-injection scope, so it is scoped. Chronicle's service registration replaces any earlier registration of it, and the ScopedAttribute makes convention binding agree when it is the only registration. Event stores created by IChronicleClient own a serializer directly instead of resolving one from the root provider.
Constructors
EventSerializer(IClientArtifactsProvider, IClientArtifactsActivator, IEventTypes, JsonSerializerOptions, IDerivedTypes?)
Initializes a new instance of the EventSerializer class.
public EventSerializer(IClientArtifactsProvider clientArtifacts, IClientArtifactsActivator artifactActivator, IEventTypes eventTypes, JsonSerializerOptions serializerOptions, IDerivedTypes? derivedTypes = null)
Parameters
clientArtifactsIClientArtifactsProviderOptional IClientArtifactsProvider for the client artifacts.
artifactActivatorIClientArtifactsActivatorIServiceProvider for resolving instances.
eventTypesIEventTypesIEventTypes for resolving event types.
serializerOptionsJsonSerializerOptionsThe common
. derivedTypesIDerivedTypesIDerivedTypes for serializing polymorphic event content adorned with DerivedTypeAttribute. Defaults to the derived types of the current type universe.
Methods
Deserialize(AppendedEvent)
Get the deserialized content from an AppendedEvent.
public Task<object> Deserialize(AppendedEvent @event)
Parameters
eventAppendedEventAppendedEvent to get content from.
Returns
Deserialize(Type, JsonObject)
Deserialize a JSON representation of an event to a specific type.
public Task<object> Deserialize(Type type, JsonObject json)
Parameters
typeTypeType to deserialize to.
jsonJsonObjectJSON to deserialize.
Returns
Serialize(object)
Serialize an event to JSON.
public Task<JsonObject> Serialize(object @event)
Parameters
eventobjectThe event instance to serialize.
Returns
- Task<JsonObject>
Serialized JSON.