You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey there, I was wondering about the opinions regarding using ApiEndpoints.
Reasoning:
The oolldd structure was to have a big controller that had action methods that called the underlying services, causing the controllers to become big.
The solution was to that problem was to introduce MediatR - (or even better imo Mediator
When you move all cross-cutting concerns out of the controllers and put them in cross-cutting middleware or filters where they belong, all your controller methods basically become something like this:
[HttpGet]
public async Task<GetUserQueryResult> GetUser([FromQuery] GetUserQuery query, CancellationToken cancellationToken)
{
var result = await _mediator.Send(query, cancellationToken);
return result;
}
So now you have a controller layer that practically does nothing besides calling a mediator layer, and a mediator layer that does nothing besides invoking the correct handler.
So I was thinking, why not just get rid of those two layers on top of the handlers? And that ApiEndpoints project seems to do exactly that. Turn your handlers into the endpoints themselves.
Taking this approach seems like a good idea, to reduce the bloilerplating of those extra layer, but I was curious about the general consensus of this approach. Or whether this might add some other issues
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey there, I was wondering about the opinions regarding using ApiEndpoints.
Reasoning:
The oolldd structure was to have a big controller that had action methods that called the underlying services, causing the controllers to become big.
The solution was to that problem was to introduce MediatR - (or even better imo Mediator
When you move all cross-cutting concerns out of the controllers and put them in cross-cutting middleware or filters where they belong, all your controller methods basically become something like this:
So now you have a controller layer that practically does nothing besides calling a mediator layer, and a mediator layer that does nothing besides invoking the correct handler.
So I was thinking, why not just get rid of those two layers on top of the handlers? And that ApiEndpoints project seems to do exactly that. Turn your handlers into the endpoints themselves.
Taking this approach seems like a good idea, to reduce the bloilerplating of those extra layer, but I was curious about the general consensus of this approach. Or whether this might add some other issues
Beta Was this translation helpful? Give feedback.
All reactions