Skip to content

Have a try to use CQRS arch design? #23

Description

@kafka-yu

Currently, we use Service/Repository architecture, it is ok for now and for a short long time.

But considering for long-term development and features growing, perhaps it could not handle them very well. Let's have a try to use CQRS (https://martinfowler.com/bliki/CQRS.html) design pattern? Then we separate query and operation into their own bus- IQueryBus, and ICommandBus. In API controller, we send a query to IQueryBus, it returns data we want.
we send a command to ICommandBus, which will handle CUD actions, and then return the response.

Take Task controller for example:
1.[GET] /api/task/1

var query = new GetTaskQuery() { 
 Id = 1,
 UserId = currentUserId, // just need to modify the query when we need to filter by userid,
};
var res = await _queryBus.SendAsync(query);
  1. [POST] /api/task
    {
    name: 'buy books'
    }
var createTaskCmd = new CreateTaskCommand() { 
 Name = name,
};
 await _commandBus.SendAsync(createTaskCmd );

var res = createTaskCmd.Result;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions