CQRS & Application Layer
The Alert.CA.Admin.API.Application project implements the Command Query Responsibility Segregation (CQRS) pattern using MediatR. Every API request flows through this layer β controllers never access repositories or services directly.
Request Pipelineβ
Module Organizationβ
The application layer is organized by domain module. Each module contains its own commands, queries, and handlers:
Alert.CA.Admin.API.Application/
βββ DeviceConfig/
β βββ Commands/
β β βββ CreateDeviceConfigCommand.cs
β β βββ UpdateDeviceConfigCommand.cs
β β βββ DeleteDeviceConfigCommand.cs
β βββ Queries/
β βββ GetAllDeviceConfigsQuery.cs
β βββ GetDeviceConfigByIdQuery.cs
βββ ImageAcquisition/
β βββ Commands/
β βββ Queries/
βββ AxisCamera/
β βββ Commands/
β βββ Queries/
βββ UserAgencyCamera/
β βββ Commands/
β βββ Queries/
βββ Users/
βββ Locations/
βββ FeatureFlags/
βββ ActivityLog/
βββ EsriMapSync/
βββ Commands/
β βββ ConvertToArcgisJsonCommand.cs
β βββ QueryEsriObjectIdsCommand.cs
β βββ DeleteEsriFeaturesCommand.cs
β βββ UploadEsriFeaturesCommand.cs
β βββ FullEsriMapSyncCommand.cs
βββ Queries/
β βββ GetEsriSyncConfigQuery.cs
β βββ GetEsriCameraDataQuery.cs
β βββ GetEsriTokenQuery.cs
βββ Models/
Audit Behaviorβ
The AuditBehavior<TRequest, TResponse> is a MediatR pipeline behavior that automatically logs audit records for any command implementing IAuditCommand:
What Gets Auditedβ
- Who β User identity from JWT claims
- What β Command type and parameters
- When β Timestamp
- Result β Success or failure
This ensures every write operation has a traceable audit trail without requiring individual handlers to implement logging.
Registered Servicesβ
The DependencyInjection class registers all application-layer services:
| Service | Interface | Purpose |
|---|---|---|
| Onboarding Service | IOnboardingService | Multi-step camera onboarding workflow |
| Bulk Operations Service | IBulkOperationsService | Batch camera operations |
| Location File Service | ILocationFileService | Location data file parsing and import |
| Durable Entity Service | IDurableEntityService | Interaction with Durable Functions entities |
| Feature Layer Service | IFeatureLayerService | ESRI feature layer updates |
| UCSD Client | IUCSDClient | UCSD Metadata API integration |
| ESRI Client | IESRIClient | ESRI GIS service integration |
| ESRI Map Sync Service | IEsriMapSyncService | Full ESRI map layer sync workflow |
Adding a New Featureβ
To add a new feature to the Admin API:
- Create a command or query in the appropriate module under
Alert.CA.Admin.API.Application - Create a handler implementing
IRequestHandler<TRequest, TResponse> - If the command modifies data, implement
IAuditCommandto get automatic audit logging - Add a controller action in
Alert.CA.Admin.APIthat calls_mediator.Send(command) - MediatR auto-discovers handlers β no manual registration needed