This project demonstrates fundamental backend concepts using ASP.NET Web API, including:
- Basic endpoint routing with
ApiController - Simulating a database using a
DummyDBand corresponding dummy controllers - Registering dependencies and using Inversion of Control (IoC)
- Understanding different service lifecycles
- Integrating a real database with Entity Framework (EF) and an ORM
- Implementing JWT-based authentication
- Securing endpoints with role-based token policies
Note: Performance and scalability were not primary considerations for this demo. The focus is on showing core concepts. Feel free to improve features like error handling, adding more endpoints, etc.
Files:
- An entity representing a user in the dummy database
- A simple implementation of the dummy database (list manipulation)
Folder: \Database\DBContainer
populate.sql: Script to populate data in the databaseDockerfile: Configuration for a PostgreSQL image
Folder: \Database\Entities
Admin-> RepresentsAdminstablePost-> RepresentsPoststableUsers-> RepresentsUserstable
AppDbContext
- Maps classes to tables and configures relationships
- DummyControllers
Demonstrates basic routing, introduces API controllers, and shows dependency injection. - ImprovedDummyControllers
Uses an actual database to store and retrieve data. - Controller
Combines database usage with authorization features.
Contains shared classes (e.g., Credentials) used to pass data within the project.
Example: Instead of exposing the entire
Userobject for login, only passnicknameandpassword.
Hosts common classes used by controllers. These services are registered for dependency injection.
-
Download and Install
- Visit Microsoft’s .NET downloads page.
- Find and download the .NET 8 installer for your operating system (Windows, macOS, or Linux).
- Follow the on-screen instructions to complete the installation.
-
Verify Installation
- Open your terminal or command prompt.
- Run:
dotnet --version
- You should see a version number starting with
8(e.g.,8.0.100).
-
Open Your Project Folder
- Navigate to the directory containing your
.csprojfile (./Workshop_Basics).
- Navigate to the directory containing your
-
Build and Restore Dependencies
- When you build the project, dependencies are automatically installed (restored) if they are missing.
- Run:
dotnet build
-
Run the Application
- Execute:
dotnet run
- The application will start and listen on the ports specified in
launchSettings.json(e.g.,https://localhost:7101).
- Execute:
You are now set to develop and run your ASP.NET Web API project on .NET 8.
-
Install Docker
Make sure Docker is correctly installed and running. -
Build the Docker Image
Navigate toDBContainerand build from the providedDockerfile:cd /Database/DBContainerdocker build -t postgres-db:workshop . -
Create a Docker Volume
docker volume create database_data
-
Create a Docker Volume
docker run -d \ --name postgres-container \ -p 5432:5432 \ -v database_data:/var/lib/mysql \ postgres-db:workshop
Starting and stopping container Starting the container
docker start postgres-containerStopping the container
docker stop postgres-containerRun first migration
dotnet ef migrations add InitialCreateMake sure that database is on
dotnet ef database updatepsql -h localhost -U akmalchik -d workshopdb -f populate.sqlYou will be asked to enter password "ieeecs@usf|is|amazing"
-
Practice Coding Challenges
- Use platforms like LeetCode or HackerRank to hone problem-solving skills.
- Combine algorithmic thinking with practical development experience.
-
Master Programming Fundamentals
- Focus on core concepts such as variables, data types, control flow, and object-oriented programming.
- Build small console applications to strengthen your foundation.
-
Use Git/GitHub Early
- Familiarize yourself with version control for managing and collaborating on code.
- Create your own GitHub repository to store and showcase your projects.
-
Understand HTTP & Basic Web Development
- Learn how web requests and responses function (methods, headers, status codes).
- Explore how RESTful APIs are structured and consumed.
-
Explore Databases & ORMs
- Study both SQL and NoSQL databases, focusing on CRUD operations.
- Practice using an ORM (or direct database queries) to interact with data.
-
Implement Authentication & Authorization
- Understand foundational security concepts.
- Experiment with different methods (JWT, OAuth, etc.) to protect your applications.
-
Try Real-Time Features (WebSockets)
- Investigate real-time communication for chat apps, notifications, or live dashboards.
- Use libraries or frameworks that simplify WebSocket integration.
-
Add Caching
- Improve performance by using in-memory or distributed caching (e.g., Redis).
- Learn caching strategies to handle high-traffic scenarios.
-
Write Tests
- Incorporate unit tests and integration tests into your workflow.
- Adopt test-driven development (TDD) practices to maintain code quality.
-
Host & Set Up CI/CD
- Deploy your applications to a hosting service or cloud platform.
- Automate builds, tests, and deployments to streamline development.
-
Experiment with Architectures
- Compare monolithic vs. microservices designs.
- Understand when and why you’d choose one pattern over another.
- Learn Advanced Topics
- Delve into areas like cloud computing, message brokers, containerization (Docker), and orchestration (Kubernetes).
- Expand your knowledge of distributed systems, scalability, and resilience.
Remember: Mastery takes time—there’s no need to rush. Consistent practice is key: the more you apply what you learn, the more proficient you become. Enjoy the journey of exploring, experimenting, and improving your projects!