Skip to content

How does it work

Clear separation between the dto and domain layer of your project

DTO Domain
Source Deserialized data from the outside world Parsed from data from the outside world
Trusted No Yes
Other features Optional validation

All input dtos have to be parsed to domain types before they can be used.

By separating the dto and domain, it means at the type level you know which types you can trust.

WebApiEndpoints only process domain types.

sequenceDiagram
    autonumber
    participant un_trusted_input as un-trusted input (DTO)
    participant input_validation as input validation
    participant trusted_domain as trusted domain
    participant web_api_endpoint as WebApiEndpoint
    participant un_trusted_output as un-trusted output (DTO)

    alt when there is input validation
        un_trusted_input-->>input_validation: input validation<br/>(optional)
        input_validation-->>un_trusted_output: [FAILURE]<br/>when input validation fails, return error
        input_validation-->>trusted_domain: mapper parses the<br/>un-trusted input into trusted domain
    end
    alt when there is no input validation
        un_trusted_input-->>trusted_domain: mapper parses the<br/>un-trusted input into trusted domain<br/>(when no input validation)
        trusted_domain-->>un_trusted_output: [FAILURE]<br/>when input parsing fails, return error
    end
    trusted_domain-->>web_api_endpoint: call web_api_endpoint
    web_api_endpoint-->>web_api_endpoint: process
    web_api_endpoint-->>un_trusted_output: mapper transforms the<br/>trusted domain into un-trusted output;

When a request is received

sequenceDiagram
    participant AspNetCoreEndpoint
    participant WebApiEndpointExecutorService
    participant WebApiEndpointDispatcher
    participant WebApiEndpointMiddlewareExecutor
    participant WebApiEndpointMiddleware
    participant WebApiEndpoint
    AspNetCoreEndpoint->>WebApiEndpointExecutorService: Receives AspNetCoreEndpoint HttpContext
    WebApiEndpointExecutorService->>WebApiEndpointExecutorService: Get WebApiEndpoint metadata from HttpContext
    WebApiEndpointExecutorService->>WebApiEndpointExecutorService: Create / Get from pool WebApiEndpointDispatcher
    WebApiEndpointExecutorService->>WebApiEndpointDispatcher: Call WebApiEndpointDispatcher
    WebApiEndpointDispatcher->>WebApiEndpointDispatcher: Read into Request Dto from HttpContext
    WebApiEndpointDispatcher->>WebApiEndpointDispatcher: Validate Request Dto (optional)
    WebApiEndpointDispatcher->>WebApiEndpointDispatcher: Map Request Dto to Request Domain
    WebApiEndpointDispatcher->>WebApiEndpointMiddlewareExecutor : Call WebApiEndpointMiddlewareExecutor
    WebApiEndpointMiddlewareExecutor->>WebApiEndpointMiddleware : Call Middleware
    WebApiEndpointMiddleware->>WebApiEndpointMiddleware : Execute incoming Middleware
    WebApiEndpointMiddleware->>WebApiEndpoint : Call WebApiEndpoint
    WebApiEndpoint->>WebApiEndpoint : Execute WebApiEndpoint
    WebApiEndpoint->>WebApiEndpointMiddleware : return Response Domain
    WebApiEndpointMiddleware->>WebApiEndpointMiddleware : Execute outgoing Middleware<br/>return Response Domain
    WebApiEndpointMiddleware->>WebApiEndpointMiddlewareExecutor : return Response Domain
    WebApiEndpointMiddlewareExecutor->>WebApiEndpointDispatcher : return Response Domain
    WebApiEndpointDispatcher->>WebApiEndpointDispatcher : Map Response Domain to Response Dto
    WebApiEndpointDispatcher->>WebApiEndpointDispatcher : Write Response Dto to HttpContext
    WebApiEndpointDispatcher->>WebApiEndpointExecutorService : return HttpContext
    WebApiEndpointExecutorService->>AspNetCoreEndpoint : return HttpContext