A comprehensive demonstration of the Model-View-Presenter (MVP) pattern using ASP.NET Web Forms and SQLite, implementing SOLID principles and clean architecture practices.
This application demonstrates proper implementation of the MVP pattern with clear separation of concerns:
MyModelViewPresenter/
βββ Core/ # Domain layer - Business entities and contracts
β βββ Models/ # Domain entities
β β βββ Product.cs # Product entity with validation
β βββ Repositories/ # Repository contracts
β β βββ IProductRepository.cs # Data access contract
β βββ Services/ # Business service contracts
β βββ IProductService.cs # Business logic contract
βββ Infrastructure/ # Infrastructure layer - Data access and services
β βββ Repositories/ # Repository implementations
β β βββ ProductRepository.cs # SQLite data access implementation
β βββ Services/ # Service implementations
β β βββ ProductService.cs # Business logic implementation
β βββ DependencyInjection/ # DI container
β βββ ServiceContainer.cs # Simple IoC container
βββ Presentation/ # Presentation layer - MVP components
β βββ Views/ # View contracts
β β βββ IProductView.cs # View interface
β βββ Presenters/ # Presenter implementations
β β βββ ProductPresenter.cs # MVP presenter
β βββ Infrastructure/ # Presentation infrastructure
β βββ PresenterFactory.cs # Presenter factory
βββ Web/ # Web layer - ASP.NET Web Forms
β βββ Default.aspx # Home page
β βββ ProductManagement.aspx # Product management page
β βββ Site.Master # Master page with modern UI
βββ Tests/ # Unit tests
βββ ProductServiceTests.cs # Service layer tests
- Model: Domain entities (
Product) and business logic (IProductService) - View: ASP.NET Web Forms pages implementing view interfaces (
IProductView) - Presenter: Orchestrates between View and Model (
ProductPresenter)
- Abstracts data access through
IProductRepository - Enables easy testing and database switching
- Implements async operations for better performance
- Business logic encapsulated in
IProductService - Validation and business rules centralized
- Returns structured results with error handling
PresenterFactorycreates presenters with proper dependencies- Manages presenter lifecycle
- Supports dependency injection
- Simple IoC container (
ServiceContainer) - Constructor injection throughout the application
- Enables testability and loose coupling
- Each class has one reason to change
ProductServicehandles only business logicProductRepositoryhandles only data accessProductPresenterhandles only presentation logic
- Interfaces allow extension without modification
- New repositories can be added implementing
IProductRepository - New services can implement
IProductService
- All implementations can replace their interfaces
ProductRepositorycan be substituted with anyIProductRepository- Mock objects used in tests demonstrate this principle
- Interfaces are focused and cohesive
IProductViewcontains only view-related operationsIProductRepositorycontains only data operations
- High-level modules don't depend on low-level modules
- Presenters depend on service abstractions
- Services depend on repository abstractions
- Dependencies are injected through constructors
- β Create, Read, Update, Delete (CRUD) products
- β Search products by name and description
- β Form validation with custom business rules
- β Responsive modern UI with dark/light theme
- β Real-time feedback with loading states
- β SQLite database with sample data
- β Async/await throughout the application
- β Proper error handling and logging
- β Input validation and sanitization
- β Unit testing with mocking
- β Dependency injection
- β Clean architecture with separation of concerns
- Framework: .NET Framework 4.8
- Web: ASP.NET Web Forms
- Database: SQLite with Dapper ORM
- UI: Bootstrap 5 with custom styling
- Testing: MSTest with Moq
- Icons: Bootstrap Icons
- Visual Studio 2019 or later
- .NET Framework 4.8
- IIS Express (included with Visual Studio)
-
Clone the repository
git clone <repository-url> cd MyModelViewPresenter
-
Open in Visual Studio
- Open
MyModelViewPresenter.sln
- Open
-
Build the solution
- Build β Build Solution (Ctrl+Shift+B)
-
Run the application
- Set
Webas startup project - Press F5 to run
- Set
-
Database Setup
- Database is created automatically on first run
- Sample data is inserted automatically
- Database location:
Web/App_Data/products.db
-
Open Test Explorer
- Test β Test Explorer
-
Run All Tests
- Click "Run All" in Test Explorer
- Tests demonstrate proper mocking and isolation
- Testability: Easy unit testing with mocked dependencies
- Maintainability: Clear separation of concerns
- Extensibility: New features can be added easily
- Readability: Well-organized code with clear responsibilities
- Reliability: Comprehensive validation and error handling
- Performance: Async operations and optimized database access
- User Experience: Modern, responsive interface
- Scalability: Clean architecture supports growth
This application demonstrates:
-
MVP Pattern Implementation
- Proper separation of View, Model, and Presenter
- Event-driven communication between layers
-
SOLID Principles in Practice
- How to apply each principle in real code
- Benefits of following these principles
-
Clean Architecture
- Dependency flow from outer to inner layers
- Interface-based design for testability
-
Modern Web Development
- Responsive design principles
- Progressive enhancement
- Accessibility considerations
-
Best Practices
- Error handling strategies
- Validation patterns
- Testing approaches
- Comprehensive Documentation: XML comments on all public members
- Error Handling: Structured error handling with user-friendly messages
- Validation: Both client-side and server-side validation
- Logging: Debug logging for troubleshooting
- Resource Management: Proper disposal of resources
- Performance: Async operations and efficient database queries
- Modern Design: Clean, professional interface
- Responsive Layout: Works on desktop and mobile devices
- Dark/Light Theme: User preference support
- Loading States: Visual feedback during operations
- Form Validation: Real-time validation feedback
- Accessibility: Proper ARIA labels and keyboard navigation
Potential improvements for learning purposes:
- Authentication & Authorization: User management system
- Caching: In-memory or Redis caching
- Logging Framework: NLog or Serilog integration
- API Layer: REST API for external access
- Advanced Validation: FluentValidation library
- Database Migrations: Structured database versioning
- Performance Monitoring: Application insights
- Containerization: Docker support
This application serves as a comprehensive reference for implementing clean architecture principles in .NET applications, demonstrating both theoretical concepts and practical implementation details.
LLM Notice: This project contains code generated by Large Language Models such as Claude and Gemini. All code is experimental whether explicitly stated or not.