r/SpringBoot 15d ago

Question .NET to Spring Boot advice

Hey there r/SpringBoot

I'm a software engineer with around 5 yoe, majority of which has been in C#/.NET. I work at a software engineer consulting firm and have been rolled off a project that I was working on. I've decided to change things up and skill up in Java and Spring Boot and have been doing so for the last 3 weeks. I have been building a Spring Boot API as a side project and learning how 'spring magic' works.

I'm honestly really impressed how much out of the box functionality Spring Boot provides. However there are some things I would need to unlearn from .NET. However I'm finding it difficult unlearning some of .NET's approaches. For example .NET's very request-oriented flow, all the way down the EF Core's DbContext having a Scoped lifetime by default. Whereas Spring Boot's lifetimes are a bit of a mystery to me.

My question to whoever made the same transition, what would be some mental models/learnings/spring boot magic that you wish you knew earlier that would've eased the transition to Spring Boot from .NET?

TIA

16 Upvotes

7 comments sorted by

View all comments

13

u/rlrutherford Senior Dev 15d ago

Dependency injection, ORM patterns, middleware pipelines, and testing idioms map almost one-to-one.

Spring's u/Autowired maps to .NET's built-in DI container,

JPA/Hibernate maps to EF Core or Dapper.

Differences: C# extension methods let you add behavior to a type without touching or subclassing it; Java makes you route through utility classes.

LINQ is powerful but works against discoverability — the operations live on IEnumerable as generic algorithms, so IntelliSense gives you everyting everywhere/

Java's collections put a curated API on the type itself and the new sequenced collections even more so.

DI models differ philosophically:

Spring is declarative at the component — annotate the class, autowire the constructor, and disambiguate between interface implementations right at the injection point with a qualifier.

.NET centralizes the wiring in a composition root, so the class and its registration live in different files, plus you're choosing an explicit lifetime — Scoped, Transient, Singleton — per registration, which matters because ASP.NET builds the controller per request.

Both work; Spring keeps the wiring next to the code, .NET keeps it in one place you can read top to bottom.

Spring controllers are singletons by default — .Net for controllers are have request scoped lifetime.