✅ Module 1: .NET Core & ASP.NET
1.1 What is .NET Core?
-
Definition:
.NET Core is a cross-platform, open-source framework developed by Microsoft for building modern, scalable, high-performance web, desktop, cloud, and mobile applications. -
Works on Windows, Linux, macOS.
-
Provides support for REST APIs, MVC applications, microservices, and cloud-native apps.
1.2 Difference: .NET Core vs .NET Framework
Feature | .NET Framework | .NET Core |
---|---|---|
Platform | Windows only | Cross-platform |
Performance | Comparatively slower | High performance, optimized |
Deployment | Installed in Windows GAC | Can be packaged with application (self-contained) |
Open Source | Partially | Fully open source |
Future | Legacy support | Actively developed |
👉 For interviews, always mention: “.NET Core is the future because it supports microservices, Docker, and cloud deployment.”
1.3 Middleware in .NET Core
-
Definition: Software components arranged in a pipeline to handle requests & responses.
-
Every request passes through the pipeline → each middleware can process, modify, or pass the request.
-
Common middleware:
-
UseRouting()
→ enables routing. -
UseAuthentication()
→ adds authentication. -
UseAuthorization()
→ checks access control. -
UseEndpoints()
→ maps controller endpoints.
-
📌 Example:
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
1.4 Dependency Injection (DI)
-
Definition: Technique to achieve loose coupling between classes.
-
.NET Core has built-in DI container.
-
Example:
// Service interface
public interface IMessageService { string SendMessage(); }
// Service implementation
public class EmailService : IMessageService
{
public string SendMessage() => "Email sent!";
}
// Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped();
}
// Controller
public class HomeController : Controller
{
private readonly IMessageService _messageService;
public HomeController(IMessageService messageService) => _messageService = messageService;
public IActionResult Index() => Content(_messageService.SendMessage());
}
1.5 Routing
-
Definition: Process of mapping incoming requests (URLs) to controllers/actions.
-
Types:
-
Conventional Routing
Example:routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
-
Attribute Routing
Example:[Route("api/[controller]")] public class StudentController : Controller { [HttpGet("{id}")] public IActionResult Get(int id) => Ok(id); }
-
1.6 Startup.cs
-
Contains application configuration.
-
Two main methods:
-
ConfigureServices()
→ register services, DI, DB context. -
Configure()
→ setup middleware pipeline.
-
📌 Summary for Module 1:
You should be able to explain .NET Core advantages, write a simple API using controller + routing, and describe middleware & DI flow.