Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

.NET Project Types — Which to Use When

Choosing the right project type is the first decision in every .NET project. Here's every type explained.


1. Console Application

What: Runs in terminal. No GUI, no web server. Entry point = Main() / top-level statements.

When to use:

  • Learning C# fundamentals ← our C# tutorials use this
  • CLI tools (import data, generate reports, run scripts)
  • Background batch jobs
  • Testing algorithms
dotnet new console -n SchoolManagement
// Program.cs — School Management console app
var registry = new StudentRegistry();

registry.Enroll(new Student { Name = "Ravi Kumar", ClassName = "10th" });
registry.Enroll(new Student { Name = "Priya Sharma", ClassName = "10th" });

registry.PrintAllStudents();
registry.GenerateReportCard("NCA-2024-0001");

Output:

=== Student Registry ===
NCA-2024-0001 Ravi Kumar 10th 87.5%
NCA-2024-0002 Priya Sharma 10th 91.0%

2. Class Library

What: DLL file — no entry point, cannot run alone. Contains reusable code used by other projects.

When to use:

  • Shared models/entities (Student, Teacher, Subject)
  • Business logic used by multiple projects
  • Clean Architecture layers (Core, Domain, Application)
dotnet new classlib -n SchoolManagement.Core
// SchoolManagement.Core — shared across all project types
namespace SchoolManagement.Core.Models;

public class Student
{
public int Id { get; set; }
public string Name { get; set; } = "";
public string RollNumber { get; set; } = "";
public string ClassName { get; set; } = "";
public double Percentage { get; set; }
}

public interface IStudentRepository
{
Task<List<Student>> GetAllAsync();
Task<Student?> GetByIdAsync(int id);
Task<Student> AddAsync(Student student);
}

3. ASP.NET Core Web API

What: HTTP server that exposes REST endpoints. Returns JSON. No UI.

When to use:

  • Backend for Angular, React, mobile apps ← our Phase 5 project
  • Microservices
  • Any system-to-system integration
dotnet new webapi -n SchoolManagement.Api
// StudentsController.cs
[ApiController]
[Route("api/[controller]")]
public class StudentsController : ControllerBase
{
[HttpGet]
public async Task<ActionResult<List<Student>>> GetAll()
=> Ok(await _service.GetAllStudentsAsync());

[HttpGet("{id}")]
public async Task<ActionResult<Student>> GetById(int id)
{
var student = await _service.GetByIdAsync(id);
return student is null ? NotFound() : Ok(student);
}

[HttpPost]
public async Task<ActionResult<Student>> Enroll(EnrollStudentDto dto)
{
var student = await _service.EnrollAsync(dto);
return CreatedAtAction(nameof(GetById), new { id = student.Id }, student);
}
}

Endpoints generated:

GET /api/students → list all students
GET /api/students/1 → get student by id
POST /api/students → enroll new student
PUT /api/students/1 → update student
DELETE /api/students/1 → remove student

4. ASP.NET Core MVC

What: Web application with server-rendered HTML. Uses Razor views (.cshtml).

When to use:

  • Admin panels, dashboards
  • Server-rendered web apps (faster SEO)
  • Applications where frontend team is not separate
dotnet new mvc -n SchoolManagement.Web
// Controllers/StudentController.cs
public class StudentController : Controller
{
[HttpGet]
public async Task<IActionResult> Index()
{
var students = await _service.GetAllStudentsAsync();
return View(students); // renders Views/Student/Index.cshtml
}

[HttpGet]
public IActionResult Create() => View(); // renders create form

[HttpPost]
public async Task<IActionResult> Create(StudentViewModel model)
{
if (!ModelState.IsValid) return View(model);
await _service.EnrollAsync(model);
return RedirectToAction(nameof(Index));
}
}
<!-- Views/Student/Index.cshtml -->
@model List<Student>
<h2>Students</h2>
<table>
@foreach (var s in Model)
{
<tr><td>@s.Name</td><td>@s.ClassName</td><td>@s.Percentage%</td></tr>
}
</table>

5. Razor Pages

What: Page-based alternative to MVC. Each page = .cshtml + .cshtml.cs (code-behind).

When to use:

  • Simpler than MVC for page-focused apps
  • CRUD applications, admin forms
  • Prefer when each URL maps to one page
dotnet new webapp -n SchoolManagement.Pages
// Pages/Students/Index.cshtml.cs
public class IndexModel : PageModel
{
public List<Student> Students { get; set; } = new();

public async Task OnGetAsync()
{
Students = await _service.GetAllStudentsAsync();
}

public async Task<IActionResult> OnPostDeleteAsync(int id)
{
await _service.DeleteAsync(id);
return RedirectToPage();
}
}

6. Worker Service

What: Long-running background service. No HTTP endpoints. Runs as Windows Service or Linux daemon.

When to use:

  • Process attendance records at midnight
  • Send fee reminder emails weekly
  • Poll external APIs periodically
  • Message queue consumers (RabbitMQ, Azure Service Bus)
dotnet new worker -n AttendanceProcessor
💻 Try It — Console App
💡 Paste into Program.cs and press F5⌥ GitHub
public class AttendanceWorker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
_logger.LogInformation("Processing attendance at: {time}", DateTimeOffset.Now);

await ProcessDailyAttendanceAsync();
await SendAbsenceNotificationsAsync();

// Run once per day at midnight
await Task.Delay(TimeSpan.FromDays(1), stoppingToken);
}
}
}

7. Blazor WebAssembly

What: C# runs in browser (no JavaScript). Single Page App like React/Angular but with C#.

When to use:

  • Full-stack C# (same models on client and server)
  • Rich interactive web UIs without JavaScript
  • Offline-capable apps
dotnet new blazorwasm -n SchoolManagement.Blazor

8. Blazor Server

What: C# runs on server, UI updates via SignalR WebSocket. Razor-based interactive UI.

When to use:

  • Real-time dashboards
  • Live attendance tracking
  • Low-latency required

9. gRPC Service

What: High-performance RPC (Remote Procedure Call) using Protocol Buffers.

When to use:

  • Microservice-to-microservice communication (not browser)
  • High-throughput internal APIs
  • Streaming data
dotnet new grpc -n SchoolManagement.GrpcService

10. Azure Functions

What: Serverless functions — run on events (HTTP trigger, timer, queue message).

When to use:

  • Pay-per-execution (no idle cost)
  • Event-driven processing
  • Generate monthly fee reports triggered by schedule
dotnet new func -n SchoolManagement.Functions

Project Type Decision Guide

Need: Use:
──────────────────────────────────────────────────────
Learn C# / practice Console App
Shared models + interfaces Class Library
REST API for mobile/frontend Web API
Admin web UI (server-rendered) MVC or Razor Pages
Background batch processing Worker Service
Full-stack C# (no JS) Blazor WASM/Server
Microservice communication gRPC
Serverless/event-driven Azure Functions

School Management System — Project Structure

SchoolManagement/
├── src/
│ ├── SchoolManagement.Api/ ← Web API (Phase 5)
│ │ └── Controllers/
│ │ ├── StudentsController.cs
│ │ ├── TeachersController.cs
│ │ └── ExamsController.cs
│ ├── SchoolManagement.Core/ ← Class Library (shared)
│ │ ├── Models/
│ │ │ ├── Student.cs
│ │ │ └── Teacher.cs
│ │ └── Interfaces/
│ │ └── IStudentRepository.cs
│ ├── SchoolManagement.Data/ ← Class Library (EF Core)
│ │ ├── SchoolDbContext.cs
│ │ └── Repositories/
│ └── SchoolManagement.Workers/ ← Worker Service
│ └── AttendanceWorker.cs
├── tests/
│ └── SchoolManagement.Tests/ ← xUnit test project
└── SchoolManagement.sln
🤖Use AI to Learn Faster

Use ChatGPT, Claude, or Copilot to go deeper on .NET project types. Try these prompts:

  • "What is the difference between Web API and MVC in ASP.NET Core?"
  • "When should I use a Worker Service vs a scheduled task?"
  • "What is a Class Library and why do we separate models into one?"
  • "Quiz me on .NET project types — describe a use case and I pick the project type"

💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.

Next Article

NuGet Package Manager →

nexcoding.in