Is your startup.cs looking a bit like this?

startup.cs

A long list of services being added one by one to de Dependency Container?

Or (like me) are you to lazy to add a new line every time you create a new service and thus keep forgetting to do that?


This weekend I was working on some Laptop Opvang code. A quick search gave me a cleaner way to do this, which I really like.

This blog showes a nice way around this. Now you no longer have to rember to add the service to DI.

https://www.thereformedprogrammer.net/asp-net-core-fast-and-automatic-dependency-injection-setup/

One change is that I like to make is to add a static class to each namespace folder that I want to Autodiscover and add Namespace filter to the query that gives me control over what gets automatically added to the DI and ignore all the rest.

 

And then in startup.cs just run:

Over de auteur

Steven Somer

Gek op online ondernemen. Als Product Development Manager help ik je bij het realiseren van je online ambities. Ik ben productowner van het dataintegratieplatform SYNDA en oprichter van Stichting Laptop Opvang.

MAAK KENNIS MET ANKO

Benieuwd wat we voor jou kunnen betekenen?
Ik maak graag vrijblijvend kennis!

Op deze website gebruiken we tools om de website te verbeteren en je een goede, gepersonaliseerde ervaring te geven. Ga je daar mee akkoord?