So started doing abit of MediatR CQRS pattern in abit of Clean Architecture. I've been doing the Query and Commands for Database / API stuff as the articles suggest but what about general business logic?
Say I have a List of People and I want to capitalize all their Surnames right so Wibbly Wobbly becomes Wibbly WOBBLY and find people aged 30 and above.
Would it be:
public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname() { IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery()); return await _mediator.Send(new ToCapitalSurnameAndOver30(people)); }
public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname() { IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery()); return await _mediator.Send(new ToCapitalSurnameAndOver30(people)); }
ToCapitalSurnameAndOver30
ToCapitalSurnameAndOver30
simply takes a list
foreach person in people
foreach person in people
, gets the surname
ToUpperCase()
ToUpperCase()
and
if (person.Age > 30)
if (person.Age > 30)
add to another list maybe. Nothing fancy but using
_mediator.Send()
_mediator.Send()
to get to this logic
or:
public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname() { IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery()); return await _myService.ToCapitalSurnameAndOver30(people) }
public async Task<IEnumerable<People>> GetPeopleOver30WithCapitalSurname() { IEnumerable<People> people = await _mediator.Send(new GetPeopleQuery()); return await _myService.ToCapitalSurnameAndOver30(people) }
As you might find with most stuff.
In other words, should you use it for the majority of logic or just API/Database stuff.