When developing an ASP.NET Core application, you have several choices for structuring your application into different layers. Here are some common choices for each layer:
Presentation Layer
- ASP.NET Core MVC: This is the most common choice for building web applications with a clear separation of concerns. It uses the Model-View-Controller pattern.
- Razor Pages: A simpler alternative to MVC, suitable for page-focused scenarios.
- Blazor: Allows you to build interactive web UIs using C# instead of JavaScript.
Business Logic Layer
- Web API Services: Typically, you create services that encapsulate your business logic. These services can be injected into your controllers or Razor Pages.
- MediatR: A popular library for implementing the mediator pattern, which helps in decoupling business logic from the presentation layer.
- Minimal API: fast HTTP API
Data Access Layer
- Entity Framework Core (EF Core): The most widely used ORM in the .NET ecosystem. It provides a high-level abstraction for database operations.
- Dapper: A lightweight ORM that is faster than EF Core but requires more manual work.
- ADO.NET: net data access library
- Subsonic, and others ORM.
Other Considerations
- Dependency Injection (DI): ASP.NET Core has built-in support for DI, which is essential for managing dependencies in a clean and testable way.
- Logging: ASP.NET Core provides a robust logging framework that can be extended with third-party libraries like Serilog or NLog.
- Configuration: Use the built-in configuration system to manage settings across different environments.
- Caching: Implement caching strategies using in-memory caching, distributed caching, or third-party libraries like Redis.
Examples:
You want to build information system, you can use: Razor, Web API, ADO.NET, and JWT and O365 Auth