AppServices¶
An Application Service is a service that contains application/use-case logic.
Application Services implement the IAppService
marker interface, and are
automatically exposed by the MVC Module as API Controllers, by following a set
of Routing Conventions
Implementation Example¶
AppServices are defined in the Application Layer. If you have an
Application.Contracts
project, you would define an interface for your
AppService there:
C# | |
---|---|
The implementation for your service should live in the Application Layer:
- Use
async
methods 'all the way' when possible. - Always receive a
CancellationToken
and pass it down the calling chain. - Always inject interfaces, it will allow for easier testing.
- AppServices never contain domain business logic; they coordinate domain entities instead.
- AppServices receive and return DTOs.
Naming convention¶
Always use the AppService
suffix when naming application service classes. The
Suite will automatically remove it leaving your classes named properly, and your
API endpoints as well.
Auto registration¶
IAppService
implementations will be auto-registered in DI by the Suite
Framework, you don't need to take care of registering it as dependency.
Excluding AppServices¶
There may be times when you need to exclude an AppService from being registered as an API Controller.
It might be useful to exclude AppServices that are for development/diagnostics
from production builds, or perhaps even better you can enable/disable them from
IConfiguration
To exclude an AppService, we use the EndpointsModule
options, like below: