A quick/niave POC of what a clean architecture using ASP.NET Minimal APIs and Microsoft Orleans could look like with minimal plumbing.
Requirements:
- Validation of incoming HTTP request
- Mapping from HTTP model to domain object
- Minimal extra code - both from "framework" side as well as application side
HTTP [GET/POST] Request -> RequestProcessor -> RequestHandler -> (Validation (if registered), Mapping from model to domain object (if required), Hander ExecuteRequest) -> HTTP IResult Response
Clone the repo run the following command from the root of the repo:
dotnet run --project ./src/Sample.Profile.Api.Host/Sample.Profile.Api.Host.csproj
Use your favorite HTTP testing tool to send a POST request:
POST http://localhost:5000/profile
Content-Type: application/json
{
"givenName": "Clark",
"surname": "Kent",
"dateOfBirth": "1987-05-03T00:00:00.00+00:00",
"emailAddress": "clarkkent@example.com",
"phoneNumber": "5555551234"
}
Copy the guid from the location header in the response and issue new GET request:
GET http://localhost:5000/profile/f69abf28-db65-415f-bd8e-871134070272
To observe how everything works, place a breakpoint in Orleans.Cqrs.Core.RequestProcessor.ExecuteRequestAsync
of the Orleans.Cqrs.Core
project
Much of this solution could be replaced with an alternative like MediatR, however, I wanted to do this as a thought experiment and here we are.
Similar Orleans solutions exist: