Visualize DI dependencies in ASP.NET Core DI Container.
by Mauricio Rojas, on Apr 25, 2020 10:43:25 AM
I few months ago I took an old VB.NET Winforms up and modernized with WebMAP to ASP.NET Core and Angular. I added some new controllers, integrated swagger, hangfire and some other new stuff.
Everything was working fine and I jumped to some other projects.
After a few months I had to work again in this app. I just needed to add a couple of new controllers.
However I had some problems because I had forgotten a lot about the app, I did not remember all the dependencies in the DI container setup.
I thought that there should be a way to visualize all those dependencies. But sadly after a while I could not find one.
So I had to create one for myself.
In the end it was quite easy. I am posting this code in case you find this useful too.
To start, we need a reference to the IServiceCollection object. So if you have an ASP.NET Core app like me just go to your StartUp.cs file.
Ok, now that you do that you just need to iterate through the service collection. Go to your Configure(IApplicationBuilder app,...) section in Startup.cs and add the following gist:
With that code in place you can browse to this url:
Ok now you can go to any website like:
And paste that graph definition:
Ok, I know it is a little rough but it only took a couple of hours. I hope it helps you if you ever need a way to visualize your DI dependencies like me.