-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enable property & eventsource to be used with occurred in projections, allowing useful aggregations. Also added support for specifying a function to create the key directly, with even more flexibility. * Projection Key by function via KeyFromFunctionAttribute
- Loading branch information
1 parent
a10c9b4
commit 9216f63
Showing
18 changed files
with
425 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Dolittle.SDK.Events; | ||
|
||
namespace Dolittle.SDK.Projections; | ||
|
||
/// <summary> | ||
/// Use this interface to define projection key selectors. | ||
/// Instances of this interface MUST be thread safe and stateless, as they are used as singletons. | ||
/// </summary> | ||
/// <typeparam name="TEvent">The mapped event type</typeparam> | ||
public interface IKeySelector<TEvent> where TEvent : class | ||
{ | ||
/// <summary> | ||
/// Map to a <see cref="Key"/> from an event and context. | ||
/// </summary> | ||
/// <param name="event"></param> | ||
/// <param name="eventContext"></param> | ||
/// <returns>The projection key</returns> | ||
Key Selector(TEvent @event, EventContext eventContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Source/Projections/KeyFromEventSourceAndOccurredAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Dolittle.SDK.Projections; | ||
|
||
/// <summary> | ||
/// Decorates a projection method with the <see cref="KeySelectorType.Property" />. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class KeyFromEventSourceAndOccurredAttribute : Attribute, IKeySelectorAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="KeyFromEventSourceAndOccurredAttribute"/> class. | ||
/// </summary> | ||
/// <param name="propertyName">The name of the property.</param> | ||
/// <param name="occurredFormat">The date time format.</param> | ||
public KeyFromEventSourceAndOccurredAttribute(string occurredFormat) | ||
{ | ||
OccurredFormat = occurredFormat; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="OccurredFormat" />. | ||
/// </summary> | ||
public OccurredFormat OccurredFormat { get; } | ||
|
||
/// <inheritdoc/> | ||
public KeySelector KeySelector => KeySelector.EventSourceAndOccured(OccurredFormat); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Dolittle.SDK.Projections; | ||
|
||
static class KeySelectorInstance<TKeySelector, TEvent> where TKeySelector : IKeySelector<TEvent>, new() where TEvent : class | ||
{ | ||
public static TKeySelector Mapper { get; } = new(); | ||
public static KeySelector Instance { get; } = KeySelector.ByFunction<TEvent>(Mapper.Selector); | ||
} | ||
|
||
/// <summary> | ||
/// Decorates a projection method with the <see cref="KeySelectorType.Function" />. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class KeyFromFunctionAttribute<TKeySelector, TEvent> : Attribute, IKeySelectorAttribute | ||
where TKeySelector : IKeySelector<TEvent>, new() where TEvent : class | ||
{ | ||
/// <inheritdoc/> | ||
public KeySelector KeySelector => KeySelectorInstance<TKeySelector, TEvent>.Instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Dolittle. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
|
||
namespace Dolittle.SDK.Projections; | ||
|
||
/// <summary> | ||
/// Decorates a projection method with the <see cref="KeySelectorType.Property" />. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class KeyFromPropertyAndOccurredAttribute : Attribute, IKeySelectorAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="KeyFromPropertyAttribute"/> class. | ||
/// </summary> | ||
/// <param name="propertyName">The name of the property.</param> | ||
/// <param name="occurredFormat">The date time format.</param> | ||
public KeyFromPropertyAndOccurredAttribute(string propertyName, string occurredFormat) | ||
{ | ||
Expression = propertyName; | ||
OccurredFormat = occurredFormat; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="KeySelector" />. | ||
/// </summary> | ||
public KeySelectorExpression Expression { get; } | ||
|
||
/// <summary> | ||
/// Gets the <see cref="OccurredFormat" />. | ||
/// </summary> | ||
public OccurredFormat OccurredFormat { get; } | ||
|
||
/// <inheritdoc/> | ||
public KeySelector KeySelector => KeySelector.PropertyAndOccured(Expression, OccurredFormat); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.