diff --git a/src/EventSourcingTests/Projections/SingleStreamProjectionTests.cs b/src/EventSourcingTests/Projections/SingleStreamProjectionTests.cs index c66116e449..678646d4ee 100644 --- a/src/EventSourcingTests/Projections/SingleStreamProjectionTests.cs +++ b/src/EventSourcingTests/Projections/SingleStreamProjectionTests.cs @@ -1,3 +1,4 @@ +using System; using EventSourcingTests.Aggregation; using Marten; using Marten.Events; @@ -41,4 +42,15 @@ public void do_not_set_mapping_to_UseVersionFromMatchingStream_when_rich_append( mapping.UseVersionFromMatchingStream.ShouldBeFalse(); } + + [Fact] + public void you_cannot_accidentally_try_to_add_single_stream_projection_through_the_snapshot() + { + var options = new StoreOptions(); + + Should.Throw(() => + { + options.Projections.Snapshot(SnapshotLifecycle.Inline); + }); + } } diff --git a/src/Marten/Events/Projections/ProjectionOptions.cs b/src/Marten/Events/Projections/ProjectionOptions.cs index eda3d8178d..20dc6cb6d6 100644 --- a/src/Marten/Events/Projections/ProjectionOptions.cs +++ b/src/Marten/Events/Projections/ProjectionOptions.cs @@ -324,6 +324,10 @@ private MartenRegistry.DocumentMappingExpression singleStreamProjection( Action asyncConfiguration = null ) { + if (typeof(T).CanBeCastTo()) + throw new InvalidOperationException( + $"This registration mechanism can only be used for an aggregate type that is 'self-aggregating'. Please use the Projections.Add() API instead to register {typeof(T).FullNameInCode()}"); + // Make sure there's a DocumentMapping for the aggregate var expression = _options.Schema.For();