-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
Overview
Upgrade the current InMemoryTaskRepository implementation to use Azure Cosmos DB as the persistent data store. This change will demonstrate best practices for database integration in Clean Architecture while maintaining domain-driven design principles.
Background
The current implementation uses an in-memory dictionary (Dictionary<TaskId, DomainTask>) in TaskManager.Infrastructure/Repositories/InMemoryTaskRepository.cs. This is suitable for demos and testing but not production-ready.
Goals
- Replace in-memory storage with Azure Cosmos DB
- Maintain Clean Architecture boundaries (Domain → Application → Infrastructure → API)
- Follow DDD repository pattern with business-intent method names
- Support proper async/await patterns throughout
- Add appropriate configuration and dependency injection
- Ensure comprehensive test coverage
Acceptance Criteria
Code Changes (C# - @shawnewallace)
- Create
CosmosDbTaskRepositoryimplementingITaskRepository - Add Cosmos DB configuration to
appsettings.jsonandappsettings.Development.json - Update DI registration in
ServiceExtensions.csto use Cosmos DB repository - Add proper error handling and logging using
ILogger<T> - Implement partition key strategy (suggested:
/taskIdor/status) - Add necessary NuGet packages (
Microsoft.Azure.CosmosorAzure.Cosmos) - Update README with Cosmos DB configuration instructions
- Add unit tests for
CosmosDbTaskRepositoryusing Testcontainers or emulator - Add integration tests validating end-to-end functionality
Infrastructure Changes (Bicep - @mcollier)
- Create
infra/directory structure - Create
main.bicepfor Cosmos DB account provisioning - Create
cosmos.bicepmodule for Cosmos DB configuration - Add parameter files for multiple environments (dev, staging, prod)
- Create App Service Bicep module for API hosting
- Document deployment instructions in
infra/README.md - Set up environment-specific configuration
Technical Requirements
Cosmos DB Configuration
{
"CosmosDb": {
"AccountEndpoint": "https://<account-name>.documents.azure.com:443/",
"DatabaseName": "TaskManagerDb",
"ContainerName": "Tasks",
"PartitionKeyPath": "/taskId"
}
}Repository Pattern Compliance
- Maintain existing method signatures in
ITaskRepository - Use business-intent method names (not generic CRUD)
- Support
CancellationTokenfor all async operations - Return domain entities, not data transfer objects
Testing Strategy
- Unit tests with mocked Cosmos SDK client
- Integration tests with Cosmos DB Emulator or Testcontainers
- Verify partition key strategy prevents hot partitions
- Test concurrent write scenarios
Implementation Approach
Phase 1: Setup & Configuration
- Add NuGet packages to
TaskManager.Infrastructure.csproj - Create configuration classes and options pattern
- Set up dependency injection
Phase 2: Repository Implementation
- Create
CosmosDbTaskRepositoryclass - Implement each
ITaskRepositorymethod - Add proper error handling and logging
- Handle Cosmos DB-specific concerns (partition keys, consistency)
Phase 3: Testing
- Write unit tests with mocked Cosmos client
- Write integration tests with Cosmos DB Emulator
- Validate against existing acceptance tests
Phase 4: Infrastructure
- Create Bicep templates for Cosmos DB provisioning
- Set up multi-environment support
- Document deployment process
Out of Scope
- Data migration from in-memory to Cosmos DB (fresh start)
- Advanced Cosmos DB features (change feed, stored procedures)
- Multi-region replication (can be added later)
Dependencies
- Azure subscription for Cosmos DB provisioning
- Cosmos DB Emulator for local development/testing
- Bicep CLI for infrastructure deployment
References
- Azure Cosmos DB Best Practices
- Cosmos DB .NET SDK
- Clean Architecture with Cosmos DB
- Repository Copilot Instructions:
.github/copilot-instructions.md
Notes
This work item is part of the demo/coi branch demonstration. Both code and infrastructure changes will be developed in parallel by @shawnewallace (C# code) and @mcollier (Bicep infrastructure) and merged via pull requests.
Demo Focus Areas:
- Agent planning mode and work item decomposition
- Parallel development workflow
- Custom Copilot instructions for consistency
- Code review automation with
/checkcommand - Infrastructure as Code with Bicep best practices