Skip to content

Commit

Permalink
fix: do not create instances of the projection when rebuilding it
Browse files Browse the repository at this point in the history
  • Loading branch information
ethno2405 committed Aug 31, 2022
1 parent 3d27039 commit 2bbdf7a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Elders.Cronus/MessageProcessing/DynamicMessageHandle.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Elders.Cronus.Workflow;
using System.IO;
using System.Threading.Tasks;
using Elders.Cronus.Workflow;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.IO;
using System.Threading.Tasks;

namespace Elders.Cronus.MessageProcessing
{
Expand Down
22 changes: 13 additions & 9 deletions src/Elders.Cronus/Projections/ProjectionRepository.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Elders.Cronus.MessageProcessing;
using Elders.Cronus.Projections.Snapshotting;
using Elders.Cronus.Projections.Versioning;
using Microsoft.Extensions.Logging;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Elders.Cronus.MessageProcessing;
using Elders.Cronus.Projections.Snapshotting;
using Elders.Cronus.Projections.Versioning;
using Microsoft.Extensions.Logging;

namespace Elders.Cronus.Projections
{
Expand Down Expand Up @@ -120,10 +120,14 @@ public async Task SaveAsync(Type projectionType, IEvent @event, EventOrigin even
if (projectionName.Equals(version.ProjectionName, StringComparison.OrdinalIgnoreCase) == false)
throw new ArgumentException($"Invalid version. The version `{version}` does not match projection `{projectionName}`", nameof(version));

var handlerInstance = handlerFactory.Create(projectionType);
var projection = handlerInstance.Current as IProjectionDefinition;
if (projection != null)
bool isProjectionDefinitionType = typeof(IProjectionDefinition).IsAssignableFrom(projectionType);
bool isEventSourcedType = typeof(IAmEventSourcedProjection).IsAssignableFrom(projectionType);

if (isProjectionDefinitionType)
{
var handlerInstance = handlerFactory.Create(projectionType);
var projection = handlerInstance.Current as IProjectionDefinition;

var projectionIds = projection.GetProjectionIds(@event);

foreach (var projectionId in projectionIds)
Expand All @@ -142,7 +146,7 @@ public async Task SaveAsync(Type projectionType, IEvent @event, EventOrigin even
}
}
}
else if (handlerInstance.Current is IAmEventSourcedProjection eventSourcedProjection)
else if (isEventSourcedType)
{
try
{
Expand Down

0 comments on commit 2bbdf7a

Please sign in to comment.