Spring Boot to .NET 10: The DI Validation Trap

24 September 2026 dotnetaspnet-corespring-bootjavadependency-injectionef-core
PDF The design sheet The full architecture and the verified references. Free, no email.
Thumbnail for Spring Boot to .NET 10: The DI Validation Trap 6:32
Watch on YouTube, or read on below.
Run this yourself → Clone the repo, docker compose up, and watch it happen

This ASP.NET Core app refused to start in the Development environment. I ran exactly the same build as Production. It started, and then request two was given request one’s ID. Nothing changed in the code. Only the environment changed.

Everything below was run on 24 September 2026 on Spring Boot 4.1.1 and .NET 10 LTS, using ASP.NET Core’s built-in dependency injection container with the normal host defaults. Every result is reproduced by one script in the repository.

The move, in one table

Spring instinctASP.NET CoreConsequence
A missing bean stops startupProduction starts500 on the first request
Request scope finds the requestA singleton captures a scoped serviceThe first request’s ID, every time
Two candidates is an errorThe last registration winsRegistration order is behaviour
Change it inside a transactionTracking is not savingCall SaveChanges

Failed in Development, started in Production

Checkout needs a payment gateway and none is registered. In Development the app refuses to start: Unable to resolve service for type IPaymentGateway. Switch the same build to Production and it starts; the first request to checkout returns 500. The generic host documentation is explicit: it “enables scope validation and dependency validation when the environment is Development”. Outside Development, with these defaults, both checks are off.

Same ID, every request

AuditLog is registered as a singleton and depends on RequestContext, which is scoped. Built once, the singleton captures the scoped context it was given, so later requests keep seeing that captured instance:

audit log sees a5e8233b-c621-4bc2-8423-a562a8f3e995,
  this request is 503119e1-d2f1-46f5-9097-fd3700ac22f1
audit log sees a5e8233b-c621-4bc2-8423-a562a8f3e995,
  this request is 012755b8-1fbd-4683-b470-1fe8307cced7

Spring’s request scope annotation uses a scoped proxy by default, so each call finds the current request. To be fair, Spring can capture shorter lived beans in other setups; this compares ASP.NET Core scoped with Spring request scope.

Validation fixes detection, not the graph

builder.Host.UseDefaultServiceProvider(options =>
{
    options.ValidateScopes = true;
    options.ValidateOnBuild = true;
});

With both on, Production refuses to start for both mistakes, like Development. That moves when you find out. Registering the gateway, and correcting the lifetime relationship, are the fixes.

Stripe, then PayPal

Register two gateways and inject one: you get PayPal, the last registered. Ask for the list and you get both. It still starts with validation on, because two registrations are valid in the built-in container. In the Spring app, the equivalent single bean injection refuses to start, “required a single bean, but 2 were found”, and you choose with @Primary or a qualifier.

Tracking is not saving

In Spring, inside a transaction, you can change a loaded entity and never call save: JPA and Hibernate write it at commit. Translate that line for line to EF Core and commit without SaveChanges, and the database still has the old amount. EF Core can track and detect the change; it only reaches the database through SaveChanges.

Run it yourself

git clone https://github.com/code-with-sam-dev/spring-to-dotnet
cd spring-to-dotnet
docker compose up -d
scripts/verify.sh

Nothing to install for .NET: the SDK runs in Microsoft’s official container.


Watch next

New videos land on Code with Sam - subscribe there if this was useful.

Get the interview pack

A free, practical pack for engineers preparing for senior backend interviews - the questions that actually get asked, and how to answer them like someone who has done the work.

New articles and videos when they land. No spam, and one click to leave.