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);
- [POST] /api/task
{
name: 'buy books'
}
var createTaskCmd = new CreateTaskCommand() {
Name = name,
};
await _commandBus.SendAsync(createTaskCmd );
var res = createTaskCmd.Result;
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
{
name: 'buy books'
}