Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start and archive streams using aggregate handlers #1109

Open
rigtigeEmil opened this issue Oct 31, 2024 · 0 comments
Open

Start and archive streams using aggregate handlers #1109

rigtigeEmil opened this issue Oct 31, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@rigtigeEmil
Copy link

rigtigeEmil commented Oct 31, 2024

Is your feature request related to a problem? Please describe.
Starting a stream is doable outside of an aggregate handler like this. It works, but it's a bit verbose, and not very easy on the eyes, so perhaps just a fancy wrapper method could do the trick

public static class MyCommandHandler
{
    public static (MyEvent, IStartStream) Handle(MyCommand command)
    {
        var @event = new MyEvent();

        return (@event, MartenOps.StartStream<MyAggregate>(@event.Id, @event));
    }
}

There does not seem to be a similar way of archiving a stream. A solution like above would suffice, even if I'm sure the Wolverine team has ideas for something even nicer. Might be;

public static class MyCommandHandler
{
    public static (MyEvent, IArchiveStream) Handle(MyCommand command)
    {
        var @event = new MyEvent();

        return (@event, MartenOps.Archive<MyAggregate>(@event.Id, @event));
    }
}

Describe the solution you'd like
In a perfect world, both these scenarios would be tied into the aggregate workflow. Starting an event could(?) be:

[AggregateHandler]
public static class MyCommandHandler
{
    public static MyEvent Handle(MyCommand command)
    {
        // if information can be inferred from the event type that something archives/starts a stream?
        return new MyEvent();
    }
}

If more information is required, maybe another attribute or something that easily wraps the handler and indicates that it's an event starting a new stream:

[AggregateHandler]
public static class MyCommandHandler
{
    [StartStream]
    public static MyEvent Handle(MyCommand command)
    {
        return new MyEvent();
    }
}

A very similar API would be very nice for archiving a stream:

[AggregateHandler]
public static class MyCommandHandler
{
    [ArchiveStream]
    public static MyEvent Handle(MyCommand command)
    {
        return new MyEvent();
    }
}
@jeremydmiller jeremydmiller added the enhancement New feature or request label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants