Understanding ASP.net core dependency injection types

When adding dependencies in asp.net core project you will see three options

  • Transient
  • Scoped
  • Singleton

Just for my mental note, trying to document it with images

The scenario is very simple, maybe not a true real-world one but whatever gets the point across. There is only one endpoint in a controller, which then calls a service which eventually calls a repository. All these rely on ILogger

In each of these, the change in color indicates a new instance

Hope these images make it easier to remember.

GraphQL vs REST vs gRPC Pizza Analogy

This is not to provide you with any technical internals or implementation details, maybe just to establish a mental model. It might come handy when deciding what to use.

Imagine you are craving Pizza. You have three options…

Order from a pizza place that has preset pizza menu. No customization of size or toppings, that’s REST.

A pizza place that allows you complete customization of size and toppings, that’s GraphQL. Probably will be slower than REST.

The third option is a frozen pizza you have it in your fridge. You already bought the kind you like, that’s gRPC. This is the fastest way you will get your pizza.

And just like Pizza relies on dough, they all rely on HTTP