Introduction
In this article, we will see the Best practice to make your project cleaner in .NET
Before we start, please take a look at my last article on Best practice to make your project cleaner in .NET CORE.
Let's get started.
The clean project principles are mostly the same, but in .NET Framework there are some differences in structure, DI, and configuration because:
-
There's no
Program.cswith minimal hosting model. -
You often work with ASP.NET MVC 5, Web API 2, or WCF instead of ASP.NET Core.
-
Dependency Injection and configuration are not built-in — you use NuGet packages (e.g., Autofac, Unity, Ninject).
Here’s the .NET Framework–specific best practices:
1. Keep a Layered Architecture
Example for ASP.NET MVC 5 / Web API 2:
MyApp.sln
├─ MyApp.Web // MVC or Web API project (Controllers, Views)
├─ MyApp.Application // Service layer (business logic, DTOs)
├─ MyApp.Domain // Entities, enums, interfaces
├─ MyApp.Infrastructure // EF6, repositories, external integrations
└─ MyApp.Tests // Unit & integration tests
Note: You can still do feature-based folders inside Web or Application.
2. Use Dependency Injection (Manually Registered)
In .NET Framework, you add a DI container manually, for example Autofac:
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterType<OrderService>().As<IOrderService>();
builder.RegisterType<OrderRepository>().As<IOrderRepository>();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
Note: Do this in Global.asax → Application_Start().
3. Keep Controllers Thin
Same as in Core: controllers only handle HTTP flow — move logic into services.
4. Use ViewModels & DTOs
-
Avoid passing EF entities directly to views or API responses.
-
Use
AutoMapperfor mapping between domain models and DTOs:

Comments
Join the conversation! Your thoughts help the community grow.