Skip to content

Monoversity-One/ASPNETCore-Essentials-Course

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ASP.NET Core Essentials

A comprehensive learning repository containing 20 focused modules that demonstrate core ASP.NET Core concepts through practical, runnable examples. Each module is a complete, self-contained project with detailed comments and interactive testing capabilities.

πŸš€ Quick Start

Prerequisites

  • .NET 8 SDK or later (Download)
  • IDE (choose one):
    • Visual Studio 2022
    • VS Code with C# Dev Kit extension
    • JetBrains Rider

Running a Module

Option 1: Visual Studio 2022

  1. Open ASPNETCore-Essentials.sln
  2. Right-click any project in Solution Explorer
  3. Select "Set as Startup Project"
  4. Press F5 or click "Run"

Option 2: VS Code

  1. Open the repository folder
  2. Install C# Dev Kit extension
  3. Open any module folder (e.g., src/01-MinimalApiBasics)
  4. Press F5 or use the Run menu

Option 3: Command Line

# Navigate to any module
cd src/01-MinimalApiBasics

# Run the project
dotnet run

# The app will start and display URLs:
# https://localhost:5001
# http://localhost:5000

Testing APIs

Most modules include Swagger UI for interactive testing:

  1. Run the module
  2. Navigate to https://localhost:{port}/swagger
  3. Expand endpoints and click "Try it out"
  4. Fill in parameters and click "Execute"

πŸ“š Modules Overview

Each module is a standalone project demonstrating specific ASP.NET Core concepts. Click the links to explore the code.

Fundamentals (1-4)

Hello world, route parameters, query strings, request binding, response types, CRUD operations, async endpoints, HTTP methods

  • 15+ endpoint examples
  • Complete CRUD operations
  • Data validation
  • Swagger documentation

Custom middleware, request pipeline, endpoint routing, route constraints, middleware ordering

  • Custom middleware components
  • Pipeline visualization
  • Route constraint examples

appsettings.json, environment variables, configuration providers, ILogger, structured logging

  • Multiple configuration sources
  • Structured logging patterns
  • Log levels and filtering

Service lifetimes (Singleton, Scoped, Transient), options pattern, typed clients, service registration

  • Service lifetime demonstrations
  • Options pattern implementation
  • Configuration binding

Web UI (5-6)

Controllers, views, layouts, partial views, tag helpers, view components, model binding

  • Complete MVC pattern
  • Razor view engine
  • Tag helpers and view components

Page models, page handlers, TempData, validation, forms, routing

  • Page-based architecture
  • Form handling
  • Model validation

Web APIs (7-10)

RESTful APIs, DTOs, model validation, API versioning, Swagger/OpenAPI documentation

  • RESTful design patterns
  • DTO mapping
  • API versioning strategies

DbContext, relationships (one-to-many), LINQ queries, filtering, pagination, aggregations, seeding data, SQLite database

  • Complete relational model
  • Advanced queries
  • Eager loading
  • Data seeding

Cookie authentication, JWT bearer tokens, identity basics, authorization policies, claims

  • Cookie-based auth
  • JWT token generation
  • Authorization policies

Action filters, exception filters, result filters, custom model binders, validation attributes

  • Custom filters
  • Model binding customization
  • Validation patterns

Performance & Reliability (11-13)

In-memory caching, response caching, distributed cache patterns, response compression (Gzip, Brotli)

  • Memory cache
  • Response caching
  • Compression middleware

IHostedService, BackgroundService, timed background tasks, queued work items, graceful shutdown

  • Hosted services
  • Background task patterns
  • Graceful shutdown handling

Health check endpoints, custom health checks, database health checks, OpenTelemetry integration, distributed tracing, metrics

  • Multiple health endpoints
  • Custom health checks
  • OpenTelemetry integration
  • Distributed tracing

Real-time & RPC (14-15)

WebSocket connections, hubs, real-time messaging, broadcasting, groups, streaming data, JavaScript client

  • Chat hub with private messages
  • Notification broadcasting
  • Stock ticker streaming
  • Interactive HTML client

Protocol Buffers, unary RPC, server streaming, client streaming, bidirectional streaming, gRPC reflection, CRUD operations

  • All 4 RPC types
  • Protocol Buffers definitions
  • gRPC reflection
  • Complete CRUD service

Security & Resilience (16-19)

Fixed window, sliding window, token bucket, concurrency limiters, per-IP limiting, custom rate limit policies

  • 6 rate limiting strategies
  • Custom rejection handlers
  • Interactive testing interface

Cross-Origin Resource Sharing policies, security headers (CSP, HSTS, X-Frame-Options), origin validation

  • Multiple CORS policies
  • Comprehensive security headers
  • Clickjacking protection
  • XSS protection

Single/multiple file uploads, chunked uploads for large files, file streaming, progress tracking, content-type detection

  • Single/multiple uploads
  • Chunked upload for large files
  • Streaming downloads
  • Progress tracking

Global exception handling, RFC 7807 Problem Details, custom exceptions, validation errors, status code pages

  • RFC 7807 implementation
  • Global exception handler
  • Custom exception types
  • Standardized error responses

Testing (20)

Unit tests with xUnit, integration tests with WebApplicationFactory, mocking with NSubstitute, FluentAssertions, test patterns (AAA), repository tests, service tests, API tests

  • 23 unit tests
  • 13 integration tests
  • Mocking with NSubstitute
  • FluentAssertions
  • AAA pattern

🎯 Learning Path

Beginner Track (Weeks 1-2)

Start with modules 1-6 to understand ASP.NET Core fundamentals and web UI development.

Week 1: Core Fundamentals

  • Day 1-2: Module 01 - Minimal APIs
    • Understand endpoints, routing, request/response
    • Practice: Create your own API endpoints
  • Day 3-4: Module 02 - Middleware
    • Learn request pipeline
    • Practice: Create custom middleware
  • Day 5: Module 03 - Configuration
    • Configuration sources
    • Practice: Add custom configuration
  • Day 6-7: Module 04 - Dependency Injection
    • Service lifetimes
    • Practice: Create and inject your own services

Week 2: Web Development

  • Day 1-3: Module 05 - MVC
    • Controllers, views, models
    • Practice: Build a simple CRUD UI
  • Day 4-5: Module 06 - Razor Pages
    • Page-based architecture
    • Practice: Create form-based pages
  • Day 6-7: Module 07 - Web API
    • RESTful API design
    • Practice: Build a complete API

Intermediate Track (Weeks 3-4)

Progress through modules 7-12 to learn API development, data access, authentication, and performance optimization.

Week 3: Data & Security

  • Day 1-3: Module 08 - Entity Framework
    • Database operations, relationships
    • Practice: Design your own data model
  • Day 4-5: Module 09 - Authentication
    • Cookie and JWT auth
    • Practice: Secure your API
  • Day 6-7: Module 10 - Filters & Validation
    • Request/response pipeline customization
    • Practice: Create custom filters

Week 4: Performance & Advanced

  • Day 1-2: Module 11 - Caching
    • Memory and response caching
    • Practice: Add caching to your API
  • Day 3: Module 12 - Background Services
    • Long-running tasks
    • Practice: Create a scheduled task
  • Day 4: Module 13 - Health Checks
    • Monitoring and observability
    • Practice: Add health checks to your app
  • Day 5: Module 14 - SignalR
    • Real-time communication
    • Practice: Build a simple chat
  • Day 6: Module 15 - gRPC
    • High-performance RPC
    • Practice: Create a gRPC service
  • Day 7: Review and build a project combining multiple concepts

Advanced Track (Week 5)

Explore modules 13-20 for real-time communication, gRPC, security, error handling, and testing strategies.

Week 5: Security & Production

  • Day 1: Module 16 - Rate Limiting
    • API throttling
    • Practice: Add rate limits to your API
  • Day 2: Module 17 - CORS & Security
    • Cross-origin security
    • Practice: Secure your frontend-backend communication
  • Day 3: Module 18 - File Upload
    • File handling
    • Practice: Add file upload to your app
  • Day 4: Module 19 - Error Handling
    • Proper error responses
    • Practice: Implement global error handling
  • Day 5-7: Module 20 - Testing
    • Unit and integration testing
    • Practice: Write tests for your code

πŸ§ͺ Running Tests

All Tests

# From repository root
dotnet test

# With detailed output
dotnet test --verbosity normal

Module 20 Tests (Unified Project)

# Navigate to the testing module
cd src/20-Testing

# Run all tests (unit + integration)
dotnet test

# Watch mode (auto-run on changes)
dotnet watch test

Test Summary:

  • Unit Tests: 23 tests (ProductService, ProductRepository)
  • Integration Tests: 13 tests (Full API testing)
  • Total: 36 comprehensive tests

πŸ“‹ Module Ports Reference

Each module runs on a unique port to avoid conflicts when running multiple modules:

Module HTTPS Port HTTP Port Swagger URL
01 - Minimal API 51010 51012 https://localhost:51010/swagger
02 - Middleware 51020 51022 https://localhost:51020/swagger
03 - Configuration 51030 51032 https://localhost:51030/swagger
04 - DI & Options 51040 51042 https://localhost:51040/swagger
05 - MVC 51050 51052 https://localhost:51050
06 - Razor Pages 51060 51062 https://localhost:51060
07 - Web API 51070 51072 https://localhost:51070/swagger
08 - EF Core 51080 51082 https://localhost:51080/swagger
09 - Authentication 51090 51092 https://localhost:51090/swagger
10 - Filters 51100 51102 https://localhost:51100/swagger
11 - Caching 51110 51112 https://localhost:51110/swagger
12 - Background 51120 51122 https://localhost:51120/swagger
13 - Health Checks 51130 51132 https://localhost:51130/swagger
14 - SignalR 51140 51142 https://localhost:51140
15 - gRPC 51150 51152 N/A (use grpcurl)
16 - Rate Limiting 51160 51162 https://localhost:51160/swagger
17 - CORS 51170 51172 https://localhost:51170/swagger
18 - File Upload 51180 51182 https://localhost:51180
19 - Error Handling 51190 51192 https://localhost:51190/swagger
20 - Testing 51200 51202 https://localhost:51200/swagger

πŸ’‘ Special Module Instructions

SignalR (Module 14)

  1. Run the module: cd src/14-SignalRRealtime && dotnet run
  2. Open https://localhost:51140 in browser
  3. Use the interactive HTML client
  4. Open multiple browser tabs to test real-time features

gRPC (Module 15)

Install grpcurl from https://github.com/fullstorydev/grpcurl

# Run the module
cd src/15-GrpcServices
dotnet run

# In another terminal, test with grpcurl:
# List services
grpcurl -plaintext localhost:51152 list

# Call unary RPC
grpcurl -plaintext -d '{"name": "World"}' localhost:51152 greeter.Greeter/SayHello

# List products
grpcurl -plaintext localhost:51152 products.ProductService/GetAllProducts

Entity Framework (Module 08)

The SQLite database is created at src/08-EfCoreSqlite/store.db

# View database with VS Code SQLite extension
# Or use DB Browser for SQLite

# To reset database:
cd src/08-EfCoreSqlite
rm store.db
dotnet run  # Database will be recreated with seed data

File Upload (Module 18)

  1. Run the module: cd src/18-FileUploadDownload && dotnet run
  2. Open https://localhost:51180 in browser
  3. Use the interactive HTML interface
  4. Uploaded files are stored in src/18-FileUploadDownload/uploads/

πŸ› οΈ Technologies & Packages

Core Technologies

  • ASP.NET Core 8.0 - Web framework
  • Entity Framework Core 8.0 - ORM for data access
  • SQLite - Embedded database (no external database required)

Real-time & Communication

  • SignalR - WebSocket-based real-time communication
  • gRPC - High-performance RPC framework
  • Protocol Buffers - Efficient serialization

Observability & Monitoring

  • OpenTelemetry - Distributed tracing and metrics
  • Health Checks - Application health monitoring
  • Structured Logging - ILogger with structured data

Testing

  • xUnit - Test framework
  • NSubstitute - Mocking library
  • FluentAssertions - Fluent assertion library
  • WebApplicationFactory - Integration testing

Security & Performance

  • Rate Limiting - Built-in ASP.NET Core rate limiting
  • CORS - Cross-origin resource sharing
  • Response Compression - Gzip and Brotli compression
  • Response Caching - HTTP caching

πŸ”§ Troubleshooting

Port Already in Use

If you get a port conflict error:

  1. Edit Properties/launchSettings.json in the module
  2. Change the port numbers
  3. Save and run again

Certificate Trust Issues (HTTPS)

# Trust the development certificate
dotnet dev-certs https --trust

NuGet Package Restore Issues

# From repository root
dotnet restore

# Or for specific project
cd src/01-MinimalApiBasics
dotnet restore

Build Errors

# Clean and rebuild
dotnet clean
dotnet build

Database Issues (Module 08)

# Delete the database and restart
cd src/08-EfCoreSqlite
rm store.db
dotnet run
# Database will be recreated with seed data

πŸ“– Key Concepts Demonstrated

βœ… Minimal APIs and traditional MVC patterns
βœ… Dependency injection and service lifetimes
βœ… Configuration and logging best practices
βœ… Entity Framework Core with relationships
βœ… Authentication and authorization
βœ… Real-time communication with SignalR
βœ… High-performance RPC with gRPC
βœ… Rate limiting and security headers
βœ… Error handling and problem details
βœ… Comprehensive testing strategies
βœ… Background services and hosted services
βœ… Health checks and observability
βœ… File upload/download with streaming
βœ… CORS and web security
βœ… Caching and compression

πŸŽ“ Tips for Success

  1. Read the code comments - Each module has detailed explanations
  2. Experiment - Modify the code and see what happens
  3. Use the debugger - Set breakpoints and step through code
  4. Check the logs - Console output shows what's happening
  5. Test everything - Use Swagger, browser, or Postman
  6. Build projects - Combine concepts from multiple modules
  7. Write tests - Practice TDD with Module 20 examples

πŸ“š Additional Resources

Official Documentation

Recommended Tools

VS Code Extensions

  • C# Dev Kit - C# development support
  • REST Client - Test HTTP requests
  • SQLite Viewer - View SQLite databases
  • Thunder Client - API testing

πŸ“Š Project Statistics

  • Total Modules: 20
  • Total Test Projects: 1 (unified in Module 20)
  • Total Tests: 36 (23 unit + 13 integration)
  • Lines of Code: ~3,500+ across all modules
  • .NET Version: 8.0
  • Cross-platform: Windows, macOS, Linux

🀝 Contributing

This is a learning repository. Feel free to:

  • Fork and experiment
  • Suggest improvements via issues
  • Share your learning projects built with these concepts

πŸ“ License

MIT License - feel free to use this repository for learning and teaching purposes.

πŸš€ What's Next?

After completing these modules, you'll be ready to:

  1. Build production applications with ASP.NET Core
  2. Design RESTful APIs following best practices
  3. Implement real-time features with SignalR
  4. Create high-performance services with gRPC
  5. Secure your applications with proper authentication and authorization
  6. Monitor and observe your applications in production
  7. Write comprehensive tests for your code
  8. Handle errors gracefully with standardized responses

Happy Learning! πŸŽ‰

About

ASP.NET Core Essentials Course source code by Elliot One

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors