all InfoSec news
10 Bad Practices to Avoid in ASP.NET Core API Controllers
DEV Community dev.to
When developing controllers in ASP.NET Core, there are certain practices that should be avoided to ensure maintainability, performance, and adherence to best practices. Here are 10 things we should avoid in our controllers.
1. Tight coupling
Avoid tightly coupling in controllers with specific dependencies or frameworks. Instead, use dependency injection to inject dependencies into controllers. This promotes loose coupling and makes the code more testable and maintainable.
// Avoid:
[ApiController]
[Route("[controller]")]
public class ProductController : ControllerBase
{
ProductService productService = …
api asp asp.net core bad best practices controllers csharp dependencies dependency dotnet dotnetcore frameworks injection .net performance practices things