In the first part of our series, we outlined the user story and established a solid understanding of what we need to implement. Now, in this second part, we will focus on setting up the project structure and preparing the foundation for development.

Repository Update

The repository for this tutorial series is available on GitHub: BookShop Repository. All the code updates for this project are being committed to the main branch. You can clone or download the repository to follow along with the implementation.

ASP.NET Core 9 project structure with folders for src, test, and organized files.


All tutorial’s Link :

Step 1: Create an Empty Solution

The first step in building any project is to create a solution that will house our application. For this tutorial, we will:

  1. Open Visual Studio (or your preferred IDE).
  2. Create an Empty Solution and name it BookShop.

This solution will act as the starting point for our application development.

Step 2: Set Up the Project Structure

Before diving into writing code, it is important to maintain an organized structure for your project. This includes:

  1. Folder Structure: Create the following folders within the solution:
    • src: This folder will contain the source code for the application.
    • test: This folder will contain unit and integration tests.
  2. Files to Include:
    • .gitignore file: This file is essential for ignoring unnecessary files in your Git repository. We will generate this file using Toptal’s Gitignore Generator. In the search box, enter the following terms:
      aspnetcorevisualstudio,visualstudiocode,rider
    • README.md file: Add a README file to provide a brief description of your project. This file will serve as documentation for your repository.
  3. Git Setup:
    • Initialize a Git repository in your solution folder.
    • Ensure the .gitignore file is properly configured.

Step-by-step guide to creating an ASP.NET Core Web API 9 project with authentication.

Step 3: Before the First Commit

Before making the first commit, follow these additional steps to set up the project structure:

  1. Create an ASP.NET Core Web API Project:
  • Inside the src folder of your solution, create a new ASP.NET Core Web API project.
  • Name the project BookShop.API.
  • In the Additional Information dialog:
    • Authentication Type: Choose No Authentication.
    • Enable Docker: Check the box to add a Dockerfile.
    • Controller Options: Select Use Controllers.
  • Click Create to generate the project.
  1. Create Class Libraries:
  • Inside the src folder, create two Class Library projects:
    • BookShop.BLL for business logic.
    • BookShop.DLL for data access logic.
  • Ensure both projects are added to the solution and referenced appropriately where needed.
  1. Folder Structure:
  • Ensure the src folder contains the BookShop.API, BookShop.BLL, and BookShop.DLL projects.
Well-organized folder structure for BookShop with src and test folders in Visual Studio.

Step 4: Link to GitHub Repository

After setting up the local structure, we will connect the project to a GitHub repository:

  1. Log in to GitHub.
  2. Create a new repository and name it BookShop.
  3. Link your local project to the GitHub repository by following these steps:
    • Open a terminal or command prompt in your project directory.
    • Run the following commands:
git init
git add .
git commit -m "Initial commit"
git branch -M main 
git remote add origin <your-github-repo-url>
git push -u origin main

This will upload your project to GitHub and complete your initial setup.

Note:

Using the Toptal Gitignore Generator ensures that unnecessary files like build artifacts and IDE-specific configurations are excluded from your repository. By including filters for ASP.NET Core, Visual Studio, Visual Studio Code, and Rider, you are optimizing your project for modern application development tools.

Some External Links

  1. Microsoft Documentation: Introduction to ASP.NET Core Authentication
  2. Microsoft Documentation: ASP.NET Core Authorization
  3. GitHub: Best Practices for ASP.NET Core Projects
  4. Toptal Gitignore Generator
  5. Official Git Documentation: Setting Up a Repository
  6. Entity Framework Core Documentation
  7. Docker Documentation: Getting Started
  8. Stack Overflow: Common Issues with ASP.NET Core Authorization
  9. Pluralsight: ASP.NET Core Security Tutorials
  10. YouTube: Setting Up ASP.NET Core Authentication and Authorization

My Others Tutorial Links:

  1. Transforming Legacy Systems: Unlock Seamless Migration with the Strangler Fig Pattern (Part 1)
  2. Unlock the Secrets of ASP.NET Core 9 Authentication and Authorization: A Powerful Step-by-Step Guide (Part 1)
  3. Simplifying Microservices Communication with Ocelot in ASP.NET Core 9.0
  4. Master Simplified Microservices Communication with YARP API Gateway in ASP.NET Core 9.0
  5. Why You Should Migrate to ASP.NET Core 9: Exploring the New Features

Next Steps

With the initial setup complete, we are ready to move on to the next phase: implementing the Identity Server database and basic project structure. Stay tuned for Part 3, where we will begin writing code to bring our user story to life!

Categorized in: