this post was submitted on 09 Aug 2023
14 points (100.0% liked)

.NET

1469 readers
4 users here now

Getting started

Useful resources

IDEs and code editors

Tools

Rules

Related communities

Wikipedia pages

founded 1 year ago
MODERATORS
 

I didn't find this anywhere convenient when I was troubleshooting so I thought I'd post this here.

We have some large projects with a lot of dependency injection, and it was taking up to a minute to start a local dev API. After a lot of troubleshooting we found it was the dependency injection validation, which is optional and disabled in production - you can turn it off using:

webBuilder.UseDefaultServiceProvider(o =>
{
  o.ValidateScopes = true;
  o.ValidateOnBuild = false;
});

in the ConfigureWebHostDefaults() section, before the webBuilder.UseStartup() call. (I'm pretty sure this is the default template but it's been a while since I set it up..)

Saves around 50 seconds when waiting for a local API to start - obviously you don't get nice messages if you've created an issue with your dependencies so be aware of that.

I'd probably also explicitly disable ValidateScopes when it's not a dev environment but that has a lower performance impact.

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 1 year ago (1 children)

It always seemed like something that could be handled by a unit test. Assuming your registration code is able to be called independently, validating it once with a test at build time seems much more useful than wasting time at every startup for something that will be more or less static.

[–] [email protected] 1 points 1 year ago

yeah, our unit tests def won't pass if we have a dependency loop so it's a waste of time checking every build.

it was crazy how difficult it was to find info on the setting and the right place to set it, considering the impact it was having.

[–] [email protected] 1 points 1 year ago

Does this apply to ASP.NET Web Forms? :) Legacy dev is where the money's at, just be prepared to stare at build output for 95% of your life.