← All posts
~/blog/what-ten-years-of-dotnet-taught-me-to-stop-doing.md#dotnet #architecture

What ten years of .NET taught me to stop doing

Most advice is about what to start doing. After ten years of backend work, mostly .NET, my best improvements came from stopping. Here are the habits I dropped, and why.

1. Wrapping Entity Framework in a repository

The classic setup is IUserRepository over a UserRepository over DbContext. But DbContext is already a unit of work, and DbSet is already a repository. A thin wrapper on top adds files and indirection, and it usually leaks anyway the moment someone needs an Include or a projection.

I now query DbContext directly in the code that needs the data, and keep queries that get reused in one named place. If I ever need to swap the database, I’ll deal with it then. I’ve almost never needed to.

2. Making an interface for every class

An interface with exactly one implementation, and no plan for a second, is just a second file to keep in sync. I used to do it because it looked like good design. Now I add an interface when there’s a real reason: two implementations, a boundary I want to fake in tests, or a public contract for a library.

Dependency injection works fine with concrete classes. Use that until it hurts.

3. Splitting into services too early

Microservices solve a real problem: many teams that need to deploy on their own. If you don’t have that problem, you’ve bought the cost without the benefit. Network calls, versioning between services, tracing a request across five logs, and a database each.

A well-organised single application, with clear folders and clear boundaries, goes a very long way. Split when a specific part has a specific reason to be separate, not because the diagram looked tidy.

4. Reaching for a generic abstraction on the second use

The first time you write something, write it. The second time, copy it if you must. The third time, you finally know what’s actually common, and you can abstract it. Abstracting on the second use means guessing, and the guess is often wrong. Wrong abstractions are harder to remove than duplicated code.

5. Mapping everything with a library, automatically

Auto-mapping saves typing and costs clarity. When a field is missing or renamed, nothing tells you at compile time. Explicit mapping is boring code, but you can read it, search it, and step through it. For small objects I just write the assignment.

6. Treating the “clever” version as the senior version

I used to be proud of short, dense code. Then I had to read my own dense code six months later. Now the test is simple: could someone tired, on a Friday, understand this without asking me? If not, I rewrite it, even if the new version is longer.

7. Skipping the boring tests, then trusting the exciting ones

Early on I wrote tests for the interesting parts and skipped the dull ones, like validation and edge cases around dates and money. Those dull parts are where the bugs live. These days I write the boring tests first.

What stays

None of this means “never use a repository” or “never use an interface”. It means asking what a thing is for before adding it. A pattern with a reason behind it is fine. A pattern added because it looks professional is just weight.

If I could give my younger self one rule, it would be this: the best code you ship is the code you decided not to write.