Skip to main content

Backend Development

Backend services follow Clean Architecture with Web, Application, Domain, and Infra layers.

Handler Pattern

Controllers inject handlers with [FromServices], and handlers extend HandlerBase<TRequest, TResponse>.

[HttpPost("foo")]
public async Task<IServiceResponse<FooResponse>> FooAsync(
[FromServices] FooHandler handler,
[FromBody] FooRequest request) => await handler.ProcessAsync(request);

public class FooHandler : HandlerBase<FooRequest, FooResponse>
{
protected override Task ValidateAsync()
{
if (string.IsNullOrWhiteSpace(Input.Name))
Response.AddError("Name is required.");

return Task.CompletedTask;
}

protected override async Task HandleAsync()
{
Response.Data = await service.DoAsync(Input);
}
}

Feature Checklist

  1. Add domain entity and repository interface.
  2. Add EF mapping, DbSet<T>, repository implementation, and infrastructure registration.
  3. Add application service, handler request, handler response, and handler.
  4. Add a Web controller action using [FromServices] handler injection.
  5. Add an EF migration targeting the Infra project with the Web startup project.