How sakopov/dapper.ambientcontext works
Main Components
a. Core Components:
• AmbientDbContext (Central Component)
• Storage System
• Connection Factory
• Context Factory
• Context Locator
• Query Proxy System
b. Integration Points:
• Dapper Integration
• Application Entry Points
• Database Connection
Top Layer (Application Layer):
• Show sample applications (Console & Web) integration points
• Demonstrate where context is initialized
Middle Layer (Core Library):
• AmbientDbContext as the central component
• Storage providers (AsyncLocal and LogicalCallContext)
• Context management components
• Query proxy system
Bottom Layer (Infrastructure):
• Database connection
• Dapper integration
Component Relationships
• Application → AmbientDbContext (Context initialization)
• AmbientDbContext → Storage Providers (Context storage)
• AmbientDbContext → Connection Factory (Database connectivity)
• Query Proxy → AmbientDbContext (Query execution)
• AmbientDbContext → Dapper (Underlying data access)
Detailed Component Breakdown
a. Storage Provider System:
• AsyncLocalContextStorage
• LogicalCallContextStorage
• IContextualStorage interface
b. Context Management:
• AmbientDbContextFactory
• AmbientDbContextLocator
• AmbientDbContextStorageProvider
c. Query Execution Flow:
• IAmbientDbContextQueryProxy
• Query execution pipeline
• Transaction handling
Implementation Notes
Highlight:
• Thread-safety mechanisms
• Async support
• Transaction scope
• Connection lifetime management
• The ambient nature of the context
• How the context flows through different parts of the application
• Transaction and connection management
• Integration with existing Dapper functionality
Remember to:
• Clear boundaries between components
• Direction of data/control flow
• Document any important assumptions or constraints
• How the ambient context pattern is implemented
• How database connections and transactions are managed
• How the library integrates with existing applications
• The flow of control through the system