Command result of command / request is required

I am trying to create an ASP.NET MVC application with the following CQRS pattern (this is my first taste of CQRS). I understand that the command part has no result. In this answer, @Johannes Rudolph said that if we need a result on the team side, we can create an event and sign to solve the problem. Now suppose we create a login page:

public class AuthController : Controller {

    private ICommandHandler<LoginCommand> _handler;

    public AuthController(ICommandHandler<LoginCommand> handler) {
        _handler = handler;
    }

    public ActionResult Login(LoginModel model) {
        if(ModelState.IsValid) {
            var cmd = new LoginCommand(model.Username, model.Password);
            _handler.Handle(cmd);
            // how to notify about login success or failed?
        }
        return View(model);
    }
}

How can I notify of a successful login command or failed? I know that I can create an event in LoginCommandand subscribe to it in the method above. But my subscription is a separate method and cannot return (for example :) the specified view. Cm:

    public ActionResult Login(LoginModel model) {
        if(ModelState.IsValid) {
            var result = true;
            var cmd = new LoginCommand(model.Username, model.Password);
            cmd.CommandCompleted += e => { result = e; };
            _handler.Handle(cmd);
            // is this correct?
            if(result)
                // redirect to ReturnUrl
            else
                // something else
        }
        return View(model);
    }

? ? ?

+5
5

CQRS - . . . , . , .

. . . , . (e g: StartDate ). , . (: "", ?) , (, AR "House" , ...)

. . , . , - .

async, , - . , , .

, ( ), , . . , . , , , , , .

, , , ,

[]

:

public class CommandValidation 
{

    public List<ValidationMessage> Messages { get; private set; }
}

CQRS , . , . .

[/Edit]

+8

, async CQRS . / , , .

( ) eventualy .

"". , -, , , .Send() . . , (, Guid.NewGuid()) , .

, UserAuthenticated of AuthenticationFailed, CommandId, , , , ..

asp.net .

:

  • , js
  • - SignalR .

. javascript X ( 1), , SignalR ( 2).

1 , 2 . , , , 1 . 2 , (, ), , .

, , , , .

- 2, , , .

, AsyncController, , . , - , , , -, -.

, , CQRS , - (, CRUD), , , -.

, Udi Dahan CQRS SOA, , CQRS.

, CQRS:)

( , )

+15

CQRS? , .

: - , CQRS. CQRS , . , , .

: , , , , - .

+6

, CQRS . , , . , , . (: - "" , AJAX TPL-, , - .)

, , " ", , , , , , - , . - , , , , .

+5

ASP.MVC. , -, - IO.

+3

All Articles