Skip to content

Commit

Permalink
Made some of the older attributes inherit from MartenDocumentAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed May 31, 2024
1 parent 63f0f02 commit 222cd79
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/Marten/Events/Aggregation/IAggregateProjection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
using Marten.Events.Daemon;
using Marten.Events.Projections;

namespace Marten.Events.Aggregation;
Expand All @@ -16,12 +17,14 @@ public interface IAggregateProjection // THIS NEEDS TO REMAIN PUBLIC

Type[] AllEventTypes { get; }

ProjectionLifecycle Lifecycle { get; }
ProjectionLifecycle Lifecycle { get; set; }

bool MatchesAnyDeleteType(StreamAction action);
bool MatchesAnyDeleteType(IEventSlice slice);
bool AppliesTo(IEnumerable<Type> eventTypes);

AsyncOptions Options { get; }


/// <summary>
/// Specify that this projection is a non 1 version of the original projection definition to opt
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Events/Projections/ProjectionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public abstract class ProjectionBase : EventFilterable
/// <summary>
/// The projection lifecycle that governs when this projection is executed
/// </summary>
public ProjectionLifecycle Lifecycle { get; internal set; } = ProjectionLifecycle.Async;
public ProjectionLifecycle Lifecycle { get; set; } = ProjectionLifecycle.Async;


/// <summary>
Expand Down
39 changes: 37 additions & 2 deletions src/Marten/Events/Projections/ProjectionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal IProjection[] BuildInlineProjections(DocumentStore store)
/// <param name="lifecycle"></param>
/// <param name="projectionName">
/// Overwrite the named identity of this projection. This is valuable if using the projection
/// asynchonously
/// asynchronously
/// </param>
/// <param name="asyncConfiguration">
/// Optional configuration including teardown instructions for the usage of this
Expand Down Expand Up @@ -177,6 +177,41 @@ public void Add(
}
}

/// <summary>
/// Register a projection to the Marten configuration
/// </summary>
/// <param name="projection">Value values are Inline/Async, The default is Inline</param>
/// <param name="lifecycle"></param>
/// <param name="projectionName">
/// Overwrite the named identity of this projection. This is valuable if using the projection
/// asynchronously
/// </param>
/// <param name="asyncConfiguration">
/// Optional configuration including teardown instructions for the usage of this
/// projection within the async projection daempon
/// </param>
public void Register(
IProjectionSource source,
ProjectionLifecycle lifecycle,
Action<AsyncOptions> asyncConfiguration = null
)
{
if (source is ProjectionBase p)
{
p.AssembleAndAssertValidity();
p.Lifecycle = lifecycle;
}

if (lifecycle == ProjectionLifecycle.Live && source is IAggregateProjection aggregateProjection)
{
// Hack to address https://github.com/JasperFx/marten/issues/2610
_options.Storage.MappingFor(aggregateProjection.AggregateType).SkipSchemaGeneration = true;
}

asyncConfiguration?.Invoke(source.Options);
All.Add(source);
}

/// <summary>
/// Add a projection that will be executed inline
/// </summary>
Expand Down Expand Up @@ -296,7 +331,7 @@ public void Add<TProjection>(
}

/// <summary>
/// Register an aggregate projection that should be evaluated inline
/// Register an aggregate projection
/// </summary>
/// <param name="projection"></param>
/// <typeparam name="T"></typeparam>
Expand Down
4 changes: 2 additions & 2 deletions src/Marten/MartenServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ public MartenConfigurationExpression AddProjectionWithServices<T>(ProjectionLife
ProjectionType = typeof(T)
};

opts.Projections.Add(projection, lifecycle);
opts.Projections.Register(projection, lifecycle);
});
break;
}
Expand Down Expand Up @@ -827,7 +827,7 @@ public MartenConfigurationExpression AddProjectionWithServices<T>(ProjectionLife
ProjectionName = projectionName
};

opts.Projections.Add(projection, lifecycle, projectionName);
opts.Projections.Register(projection, lifecycle);
});
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/DatabaseSchemaNameAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Marten.Schema;
/// Overrides the database schema name for the document type
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class DatabaseSchemaNameAttribute: MartenAttribute
public class DatabaseSchemaNameAttribute: MartenDocumentAttribute
{
private readonly string _name;

Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/DocumentAliasAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Marten.Schema;
/// types
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class DocumentAliasAttribute : MartenAttribute
public class DocumentAliasAttribute : MartenDocumentAttribute
{
public DocumentAliasAttribute(string alias)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/SoftDeletedAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Marten.Schema;
/// Marks a document type as "soft deleted"
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class SoftDeletedAttribute: MartenAttribute
public class SoftDeletedAttribute: MartenDocumentAttribute
{
/// <summary>
/// Creates an index on deleted documents
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Schema/UseOptimisticConcurrencyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Marten.Schema;
/// Directs Marten to use optimistic versioning checks when updating this document type
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class UseOptimisticConcurrencyAttribute: MartenAttribute
public class UseOptimisticConcurrencyAttribute: MartenDocumentAttribute
{
public override void Modify(DocumentMapping mapping)
{
Expand Down

0 comments on commit 222cd79

Please sign in to comment.