Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Marten generated code for event storage and projections
using CommandLineRunner;
using Marten;
using Marten.AsyncDaemon.Testing;
using Marten.AsyncDaemon.Testing.TestingSupport;
using Marten.Events;
using Marten.Events.Aggregation;
using Marten.Internal.Storage;
using Marten.Storage;
using System;
using System.Linq;
namespace Marten.Generated
{
// START: GeneratedEventDocumentStorage
public class GeneratedEventDocumentStorage : Marten.Events.EventDocumentStorage
{
private readonly Marten.StoreOptions _options;
public GeneratedEventDocumentStorage(Marten.StoreOptions options) : base(options)
{
_options = options;
}
public override Marten.Internal.Operations.IStorageOperation AppendEvent(Marten.Events.EventGraph events, Marten.Internal.IMartenSession session, Marten.Events.StreamAction stream, Marten.Events.IEvent e)
{
return new Marten.Generated.AppendEventOperation(stream, e);
}
public override Marten.Internal.Operations.IStorageOperation InsertStream(Marten.Events.StreamAction stream)
{
return new Marten.Generated.GeneratedInsertStream(stream);
}
public override Marten.Linq.QueryHandlers.IQueryHandler<Marten.Events.StreamState> QueryForStream(Marten.Events.StreamAction stream)
{
return new Marten.Generated.GeneratedStreamStateQueryHandler(stream.Id);
}
public override Marten.Internal.Operations.IStorageOperation UpdateStreamVersion(Marten.Events.StreamAction stream)
{
return new Marten.Generated.GeneratedStreamVersionOperation(stream);
}
public override void ApplyReaderDataToEvent(System.Data.Common.DbDataReader reader, Marten.Events.IEvent e)
{
if (!reader.IsDBNull(3))
{
var sequence = reader.GetFieldValue<long>(3);
e.Sequence = sequence;
}
if (!reader.IsDBNull(4))
{
var id = reader.GetFieldValue<System.Guid>(4);
e.Id = id;
}
var streamId = reader.GetFieldValue<System.Guid>(5);
e.StreamId = streamId;
if (!reader.IsDBNull(6))
{
var version = reader.GetFieldValue<long>(6);
e.Version = version;
}
if (!reader.IsDBNull(7))
{
var timestamp = reader.GetFieldValue<System.DateTimeOffset>(7);
e.Timestamp = timestamp;
}
if (!reader.IsDBNull(8))
{
var tenantId = reader.GetFieldValue<string>(8);
e.TenantId = tenantId;
}
var isArchived = reader.GetFieldValue<bool>(9);
e.IsArchived = isArchived;
}
public override async System.Threading.Tasks.Task ApplyReaderDataToEventAsync(System.Data.Common.DbDataReader reader, Marten.Events.IEvent e, System.Threading.CancellationToken token)
{
if (!reader.IsDBNull(3))
{
var sequence = reader.GetFieldValue<long>(3);
e.Sequence = sequence;
}
if (!reader.IsDBNull(4))
{
var id = reader.GetFieldValue<System.Guid>(4);
e.Id = id;
}
var streamId = await reader.GetFieldValueAsync<System.Guid>(5, token);
e.StreamId = streamId;
if (!reader.IsDBNull(6))
{
var version = reader.GetFieldValue<long>(6);
e.Version = version;
}
if (!reader.IsDBNull(7))
{
var timestamp = reader.GetFieldValue<System.DateTimeOffset>(7);
e.Timestamp = timestamp;
}
if (!(await reader.IsDBNullAsync(8, token)))
{
var tenantId = await reader.GetFieldValueAsync<string>(8, token);
e.TenantId = tenantId;
}
var isArchived = await reader.GetFieldValueAsync<bool>(9, token);
e.IsArchived = isArchived;
}
}
// END: GeneratedEventDocumentStorage
// START: AppendEventOperation
public class AppendEventOperation : Marten.Events.Operations.AppendEventOperationBase
{
private readonly Marten.Events.StreamAction _stream;
private readonly Marten.Events.IEvent _e;
public AppendEventOperation(Marten.Events.StreamAction stream, Marten.Events.IEvent e) : base(stream, e)
{
_stream = stream;
_e = e;
}
public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session)
{
var parameters = builder.AppendWithParameters("insert into cli.mt_events (data, type, mt_dotnet_type, seq_id, id, stream_id, version, timestamp, tenant_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Jsonb;
parameters[0].Value = session.Serializer.ToJson(Event.Data);
parameters[1].Value = Event.EventTypeName != null ? (object)Event.EventTypeName : System.DBNull.Value;
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters[2].Value = Event.DotNetTypeName != null ? (object)Event.DotNetTypeName : System.DBNull.Value;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint;
parameters[3].Value = Event.Sequence;
parameters[4].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[4].Value = Event.Id;
parameters[5].Value = Stream.Id;
parameters[5].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[6].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint;
parameters[6].Value = Event.Version;
parameters[7].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.TimestampTz;
parameters[7].Value = Event.Timestamp;
parameters[8].Value = Event.TenantId != null ? (object)Event.TenantId : System.DBNull.Value;
parameters[8].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
}
}
// END: AppendEventOperation
// START: GeneratedInsertStream
public class GeneratedInsertStream : Marten.Events.Operations.InsertStreamBase
{
private readonly Marten.Events.StreamAction _stream;
public GeneratedInsertStream(Marten.Events.StreamAction stream) : base(stream)
{
_stream = stream;
}
public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session)
{
var parameters = builder.AppendWithParameters("insert into cli.mt_streams (id, type, version, tenant_id) values (?, ?, ?, ?)");
parameters[0].Value = Stream.Id;
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[1].Value = Stream.AggregateTypeName != null ? (object)Stream.AggregateTypeName : System.DBNull.Value;
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
parameters[2].Value = Stream.Version;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint;
parameters[3].Value = Stream.TenantId != null ? (object)Stream.TenantId : System.DBNull.Value;
parameters[3].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Text;
}
}
// END: GeneratedInsertStream
// START: GeneratedStreamStateQueryHandler
public class GeneratedStreamStateQueryHandler : Marten.Events.Querying.StreamStateQueryHandler
{
private readonly System.Guid _streamId;
public GeneratedStreamStateQueryHandler(System.Guid streamId)
{
_streamId = streamId;
}
public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session)
{
var npgsqlParameterArray = builder.AppendWithParameters("select id, version, type, timestamp, created as timestamp, is_archived from cli.mt_streams where id = ?");
npgsqlParameterArray[0].Value = _streamId;
npgsqlParameterArray[0].DbType = System.Data.DbType.Guid;
}
public override Marten.Events.StreamState Resolve(Marten.Internal.IMartenSession session, System.Data.Common.DbDataReader reader)
{
var streamState = new Marten.Events.StreamState();
var id = reader.GetFieldValue<System.Guid>(0);
streamState.Id = id;
var version = reader.GetFieldValue<long>(1);
streamState.Version = version;
SetAggregateType(streamState, reader, session);
var lastTimestamp = reader.GetFieldValue<System.DateTime>(3);
streamState.LastTimestamp = lastTimestamp;
var created = reader.GetFieldValue<System.DateTime>(4);
streamState.Created = created;
var isArchived = reader.GetFieldValue<bool>(5);
streamState.IsArchived = isArchived;
return streamState;
}
public override async System.Threading.Tasks.Task<Marten.Events.StreamState> ResolveAsync(Marten.Internal.IMartenSession session, System.Data.Common.DbDataReader reader, System.Threading.CancellationToken token)
{
var streamState = new Marten.Events.StreamState();
var id = await reader.GetFieldValueAsync<System.Guid>(0, token);
streamState.Id = id;
var version = await reader.GetFieldValueAsync<long>(1, token);
streamState.Version = version;
await SetAggregateTypeAsync(streamState, reader, session, token);
var lastTimestamp = await reader.GetFieldValueAsync<System.DateTime>(3, token);
streamState.LastTimestamp = lastTimestamp;
var created = await reader.GetFieldValueAsync<System.DateTime>(4, token);
streamState.Created = created;
var isArchived = await reader.GetFieldValueAsync<bool>(5, token);
streamState.IsArchived = isArchived;
return streamState;
}
}
// END: GeneratedStreamStateQueryHandler
// START: GeneratedStreamVersionOperation
public class GeneratedStreamVersionOperation : Marten.Events.Operations.UpdateStreamVersion
{
private readonly Marten.Events.StreamAction _stream;
public GeneratedStreamVersionOperation(Marten.Events.StreamAction stream) : base(stream)
{
_stream = stream;
}
public override void ConfigureCommand(Weasel.Postgresql.CommandBuilder builder, Marten.Internal.IMartenSession session)
{
var parameters = builder.AppendWithParameters("update cli.mt_streams set version = ? where id = ? and version = ?");
parameters[0].Value = Stream.Version;
parameters[0].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint;
parameters[1].Value = Stream.Id;
parameters[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Uuid;
parameters[2].Value = Stream.ExpectedVersionOnServer;
parameters[2].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Bigint;
}
}
// END: GeneratedStreamVersionOperation
// START: TripAggregationLiveAggregation
public class TripAggregationLiveAggregation : Marten.Events.Aggregation.SyncLiveAggregatorBase<Marten.AsyncDaemon.Testing.TestingSupport.Trip>
{
private readonly Marten.AsyncDaemon.Testing.TestingSupport.TripAggregation _tripAggregation;
public TripAggregationLiveAggregation(Marten.AsyncDaemon.Testing.TestingSupport.TripAggregation tripAggregation)
{
_tripAggregation = tripAggregation;
}
public System.Func<Marten.AsyncDaemon.Testing.TestingSupport.Breakdown, bool> ShouldDelete1 {get; set;}
public System.Func<Marten.AsyncDaemon.Testing.TestingSupport.Trip, Marten.AsyncDaemon.Testing.TestingSupport.VacationOver, bool> ShouldDelete2 {get; set;}
public override Marten.AsyncDaemon.Testing.TestingSupport.Trip Build(System.Collections.Generic.IReadOnlyList<Marten.Events.IEvent> events, Marten.IQuerySession session, Marten.AsyncDaemon.Testing.TestingSupport.Trip snapshot)
{
if (!events.Any()) return null;
Marten.AsyncDaemon.Testing.TestingSupport.Trip trip = null;
snapshot ??= Create(events[0], session);
foreach (var @event in events)
{
snapshot = Apply(@event, snapshot, session);
}
return snapshot;
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip Create(Marten.Events.IEvent @event, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripStarted> event_TripStarted1:
return _tripAggregation.Create(event_TripStarted1.Data);
break;
}
return new Marten.AsyncDaemon.Testing.TestingSupport.Trip();
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip Apply(Marten.Events.IEvent @event, Marten.AsyncDaemon.Testing.TestingSupport.Trip aggregate, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Arrival> event_Arrival2:
_tripAggregation.Apply(event_Arrival2.Data, aggregate);
break;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Travel> event_Travel3:
_tripAggregation.Apply(event_Travel3.Data, aggregate);
break;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripEnded> event_TripEnded4:
_tripAggregation.Apply(event_TripEnded4.Data, aggregate);
break;
}
return aggregate;
}
}
// END: TripAggregationLiveAggregation
// START: TripAggregationInlineHandler
public class TripAggregationInlineHandler : Marten.Events.Aggregation.AggregationRuntime<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid>
{
private readonly Marten.IDocumentStore _store;
private readonly Marten.Events.Aggregation.IAggregateProjection _projection;
private readonly Marten.Events.Aggregation.IEventSlicer<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> _slicer;
private readonly Marten.Storage.ITenancy _tenancy;
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> _storage;
private readonly Marten.AsyncDaemon.Testing.TestingSupport.TripAggregation _tripAggregation;
public TripAggregationInlineHandler(Marten.IDocumentStore store, Marten.Events.Aggregation.IAggregateProjection projection, Marten.Events.Aggregation.IEventSlicer<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> slicer, Marten.Storage.ITenancy tenancy, Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> storage, Marten.AsyncDaemon.Testing.TestingSupport.TripAggregation tripAggregation) : base(store, projection, slicer, tenancy, storage)
{
_store = store;
_projection = projection;
_slicer = slicer;
_tenancy = tenancy;
_storage = storage;
_tripAggregation = tripAggregation;
}
public System.Func<Marten.AsyncDaemon.Testing.TestingSupport.Breakdown, bool> ShouldDelete1 {get; set;}
public System.Func<Marten.AsyncDaemon.Testing.TestingSupport.Trip, Marten.AsyncDaemon.Testing.TestingSupport.VacationOver, bool> ShouldDelete2 {get; set;}
public override async System.Threading.Tasks.ValueTask<Marten.AsyncDaemon.Testing.TestingSupport.Trip> ApplyEvent(Marten.IQuerySession session, Marten.Events.Projections.EventSlice<Marten.AsyncDaemon.Testing.TestingSupport.Trip, System.Guid> slice, Marten.Events.IEvent evt, Marten.AsyncDaemon.Testing.TestingSupport.Trip aggregate, System.Threading.CancellationToken cancellationToken)
{
switch (evt)
{
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripAborted> event_TripAborted6:
return null;
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Arrival> event_Arrival7:
aggregate ??= new Marten.AsyncDaemon.Testing.TestingSupport.Trip();
_tripAggregation.Apply(event_Arrival7.Data, aggregate);
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Travel> event_Travel8:
aggregate ??= new Marten.AsyncDaemon.Testing.TestingSupport.Trip();
_tripAggregation.Apply(event_Travel8.Data, aggregate);
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripEnded> event_TripEnded9:
aggregate ??= new Marten.AsyncDaemon.Testing.TestingSupport.Trip();
_tripAggregation.Apply(event_TripEnded9.Data, aggregate);
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripStarted> event_TripStarted10:
aggregate = _tripAggregation.Create(event_TripStarted10.Data);
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Breakdown> event_Breakdown11:
if (aggregate == null) return null;
var result_of_Invoke1 = ShouldDelete1.Invoke(event_Breakdown11.Data);
if (result_of_Invoke1)
{
return null;
}
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.VacationOver> event_VacationOver12:
if (aggregate == null) return null;
var result_of_Invoke2 = ShouldDelete2.Invoke(aggregate, event_VacationOver12.Data);
if (result_of_Invoke2)
{
return null;
}
return aggregate;
}
return aggregate;
}
public Marten.AsyncDaemon.Testing.TestingSupport.Trip Create(Marten.Events.IEvent @event, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripStarted> event_TripStarted5:
return _tripAggregation.Create(event_TripStarted5.Data);
break;
}
return new Marten.AsyncDaemon.Testing.TestingSupport.Trip();
}
}
// END: TripAggregationInlineHandler
// START: DayProjectionLiveAggregation
public class DayProjectionLiveAggregation : Marten.Events.Aggregation.SyncLiveAggregatorBase<Marten.AsyncDaemon.Testing.Day>
{
private readonly Marten.AsyncDaemon.Testing.DayProjection _dayProjection;
public DayProjectionLiveAggregation(Marten.AsyncDaemon.Testing.DayProjection dayProjection)
{
_dayProjection = dayProjection;
}
public override Marten.AsyncDaemon.Testing.Day Build(System.Collections.Generic.IReadOnlyList<Marten.Events.IEvent> events, Marten.IQuerySession session, Marten.AsyncDaemon.Testing.Day snapshot)
{
if (!events.Any()) return null;
Marten.AsyncDaemon.Testing.Day day = null;
snapshot ??= Create(events[0], session);
foreach (var @event in events)
{
snapshot = Apply(@event, snapshot, session);
}
return snapshot;
}
public Marten.AsyncDaemon.Testing.Day Create(Marten.Events.IEvent @event, Marten.IQuerySession session)
{
return new Marten.AsyncDaemon.Testing.Day();
}
public Marten.AsyncDaemon.Testing.Day Apply(Marten.Events.IEvent @event, Marten.AsyncDaemon.Testing.Day aggregate, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripStarted> event_TripStarted13:
_dayProjection.Apply(aggregate, event_TripStarted13.Data);
break;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripEnded> event_TripEnded14:
_dayProjection.Apply(aggregate, event_TripEnded14.Data);
break;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Movement> event_Movement15:
_dayProjection.Apply(aggregate, event_Movement15.Data);
break;
}
return aggregate;
}
}
// END: DayProjectionLiveAggregation
// START: DayProjectionInlineHandler
public class DayProjectionInlineHandler : Marten.Events.Aggregation.AggregationRuntime<Marten.AsyncDaemon.Testing.Day, int>
{
private readonly Marten.IDocumentStore _store;
private readonly Marten.Events.Aggregation.IAggregateProjection _projection;
private readonly Marten.Events.Aggregation.IEventSlicer<Marten.AsyncDaemon.Testing.Day, int> _slicer;
private readonly Marten.Storage.ITenancy _tenancy;
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.Day, int> _storage;
private readonly Marten.AsyncDaemon.Testing.DayProjection _dayProjection;
public DayProjectionInlineHandler(Marten.IDocumentStore store, Marten.Events.Aggregation.IAggregateProjection projection, Marten.Events.Aggregation.IEventSlicer<Marten.AsyncDaemon.Testing.Day, int> slicer, Marten.Storage.ITenancy tenancy, Marten.Internal.Storage.IDocumentStorage<Marten.AsyncDaemon.Testing.Day, int> storage, Marten.AsyncDaemon.Testing.DayProjection dayProjection) : base(store, projection, slicer, tenancy, storage)
{
_store = store;
_projection = projection;
_slicer = slicer;
_tenancy = tenancy;
_storage = storage;
_dayProjection = dayProjection;
}
public override async System.Threading.Tasks.ValueTask<Marten.AsyncDaemon.Testing.Day> ApplyEvent(Marten.IQuerySession session, Marten.Events.Projections.EventSlice<Marten.AsyncDaemon.Testing.Day, int> slice, Marten.Events.IEvent evt, Marten.AsyncDaemon.Testing.Day aggregate, System.Threading.CancellationToken cancellationToken)
{
switch (evt)
{
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripStarted> event_TripStarted16:
aggregate ??= new Marten.AsyncDaemon.Testing.Day();
_dayProjection.Apply(aggregate, event_TripStarted16.Data);
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.TripEnded> event_TripEnded17:
aggregate ??= new Marten.AsyncDaemon.Testing.Day();
_dayProjection.Apply(aggregate, event_TripEnded17.Data);
return aggregate;
case Marten.Events.IEvent<Marten.AsyncDaemon.Testing.TestingSupport.Movement> event_Movement18:
aggregate ??= new Marten.AsyncDaemon.Testing.Day();
_dayProjection.Apply(aggregate, event_Movement18.Data);
return aggregate;
}
return aggregate;
}
public Marten.AsyncDaemon.Testing.Day Create(Marten.Events.IEvent @event, Marten.IQuerySession session)
{
return new Marten.AsyncDaemon.Testing.Day();
}
}
// END: DayProjectionInlineHandler
// START: SimpleAggregateLiveAggregation
public class SimpleAggregateLiveAggregation : Marten.Events.Aggregation.SyncLiveAggregatorBase<Marten.Testing.Events.Aggregation.MyAggregate>
{
private readonly CommandLineRunner.SimpleAggregate _simpleAggregate;
public SimpleAggregateLiveAggregation(CommandLineRunner.SimpleAggregate simpleAggregate)
{
_simpleAggregate = simpleAggregate;
}
public override Marten.Testing.Events.Aggregation.MyAggregate Build(System.Collections.Generic.IReadOnlyList<Marten.Events.IEvent> events, Marten.IQuerySession session, Marten.Testing.Events.Aggregation.MyAggregate snapshot)
{
if (!events.Any()) return null;
Marten.Testing.Events.Aggregation.MyAggregate myAggregate = null;
snapshot ??= Create(events[0], session);
foreach (var @event in events)
{
snapshot = Apply(@event, snapshot, session);
}
return snapshot;
}
public Marten.Testing.Events.Aggregation.MyAggregate Create(Marten.Events.IEvent @event, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.CreateEvent> event_CreateEvent19:
return _simpleAggregate.Create(event_CreateEvent19.Data);
break;
}
return new Marten.Testing.Events.Aggregation.MyAggregate();
}
public Marten.Testing.Events.Aggregation.MyAggregate Apply(Marten.Events.IEvent @event, Marten.Testing.Events.Aggregation.MyAggregate aggregate, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.AEvent> event_AEvent20:
_simpleAggregate.Apply(event_AEvent20.Data, aggregate);
break;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.BEvent> event_BEvent21:
aggregate = _simpleAggregate.Apply(event_BEvent21.Data, aggregate);
break;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.CEvent> event_CEvent22:
_simpleAggregate.Apply(aggregate, event_CEvent22.Data);
break;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.DEvent> event_DEvent23:
aggregate = _simpleAggregate.Apply(aggregate, event_DEvent23.Data);
break;
}
return aggregate;
}
}
// END: SimpleAggregateLiveAggregation
// START: SimpleAggregateInlineHandler
public class SimpleAggregateInlineHandler : Marten.Events.Aggregation.AggregationRuntime<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid>
{
private readonly Marten.IDocumentStore _store;
private readonly Marten.Events.Aggregation.IAggregateProjection _projection;
private readonly Marten.Events.Aggregation.IEventSlicer<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> _slicer;
private readonly Marten.Storage.ITenancy _tenancy;
private readonly Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> _storage;
private readonly CommandLineRunner.SimpleAggregate _simpleAggregate;
public SimpleAggregateInlineHandler(Marten.IDocumentStore store, Marten.Events.Aggregation.IAggregateProjection projection, Marten.Events.Aggregation.IEventSlicer<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> slicer, Marten.Storage.ITenancy tenancy, Marten.Internal.Storage.IDocumentStorage<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> storage, CommandLineRunner.SimpleAggregate simpleAggregate) : base(store, projection, slicer, tenancy, storage)
{
_store = store;
_projection = projection;
_slicer = slicer;
_tenancy = tenancy;
_storage = storage;
_simpleAggregate = simpleAggregate;
}
public override async System.Threading.Tasks.ValueTask<Marten.Testing.Events.Aggregation.MyAggregate> ApplyEvent(Marten.IQuerySession session, Marten.Events.Projections.EventSlice<Marten.Testing.Events.Aggregation.MyAggregate, System.Guid> slice, Marten.Events.IEvent evt, Marten.Testing.Events.Aggregation.MyAggregate aggregate, System.Threading.CancellationToken cancellationToken)
{
switch (evt)
{
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.AEvent> event_AEvent25:
aggregate ??= new Marten.Testing.Events.Aggregation.MyAggregate();
_simpleAggregate.Apply(event_AEvent25.Data, aggregate);
return aggregate;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.BEvent> event_BEvent26:
aggregate ??= new Marten.Testing.Events.Aggregation.MyAggregate();
aggregate = _simpleAggregate.Apply(event_BEvent26.Data, aggregate);
return aggregate;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.CEvent> event_CEvent27:
aggregate ??= new Marten.Testing.Events.Aggregation.MyAggregate();
_simpleAggregate.Apply(aggregate, event_CEvent27.Data);
return aggregate;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.DEvent> event_DEvent28:
aggregate ??= new Marten.Testing.Events.Aggregation.MyAggregate();
aggregate = _simpleAggregate.Apply(aggregate, event_DEvent28.Data);
return aggregate;
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.CreateEvent> event_CreateEvent29:
aggregate = _simpleAggregate.Create(event_CreateEvent29.Data);
return aggregate;
}
return aggregate;
}
public Marten.Testing.Events.Aggregation.MyAggregate Create(Marten.Events.IEvent @event, Marten.IQuerySession session)
{
switch (@event)
{
case Marten.Events.IEvent<Marten.Testing.Events.Aggregation.CreateEvent> event_CreateEvent24:
return _simpleAggregate.Create(event_CreateEvent24.Data);
break;
}
return new Marten.Testing.Events.Aggregation.MyAggregate();
}
}
// END: SimpleAggregateInlineHandler
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment