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

CRS 2 Design #3

Open
clegendre opened this issue Jul 10, 2017 · 3 comments
Open

CRS 2 Design #3

clegendre opened this issue Jul 10, 2017 · 3 comments
Labels
Milestone

Comments

@clegendre
Copy link
Contributor

Main interface ICommandHandler is renamed to IRequestHandler (to support commands and events...) and does no longer returns a result (but Task obviously).

    public interface IRequestHandler<T>
    {
        Task HandleAsync( T request, ICommandContext context );
    }

This enforces to treat impacts of a command like pure events.
What are your thoughts about that?
Is it really what we want?
Should CRS still offers a way to return "synchronous" results of a command or should we left this usage for simple REST-like interactions ?

@clegendre clegendre added this to the CRS 2 milestone Jul 10, 2017
@clegendre
Copy link
Contributor Author

clegendre commented Jul 11, 2017

The question is: should we consider the result of a command or only its impact on the system?

@clegendre
Copy link
Contributor Author

clegendre commented Jul 11, 2017

Command 
     -> CommandHandler 
          -> Can emit Events -> EventHandler 
                   ->  Can dispatch WebSocketEvent -> WebSocket client handler
          -> Can dispatch WebSocketEvent -> WebSocket client handler

There is one constraint: WebSocketEvents can only be published by the CRS endpoint, which holds the WebSocket connection.

@clegendre
Copy link
Contributor Author

The kernel supports now both command handlers with and without results, and event handlers.
The runtime is shipped with a default asynchronous, in-memory, non-resilient implementation of IBus interface.

    public interface ICommandHandler<T> : ICommandHandler
    {
        /// <summary>
        /// Handles a request with the given <see cref="ICommandContext"/>.
        /// </summary>
        /// <remarks>
        /// If the request is like a Command, the context is the one of this command. 
        /// If the request is like an Event, the context is the original command that raises this event.</remarks>
        /// <param name="request">The request to handle.</param>
        /// <param name="context">The command context. See remarks.</param>
        /// <returns></returns>
        Task HandleAsync( T request, ICommandContext context );
    }

    public interface ICommandHandler<T, TResult> : ICommandHandlerWithResult
    {
        /// <summary>
        /// Handles a request with the given <see cref="ICommandContext"/>.
        /// </summary>
        /// <remarks>
        /// If the request is like a Command, the context is the one of this command. 
        /// If the request is like an Event, the context is the original command that raises this event.</remarks>
        /// <param name="request">The request to handle.</param>
        /// <param name="context">The command context. See remarks.</param>
        /// <returns></returns>
        Task<TResult> HandleAsync( T request, ICommandContext context );
    }

    public interface IEventHandler<T>: IEventHandler
    {
        Task HandleAsync( T request, ICommandContext context );
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant