Dependency Injection and ConfigureServices
Registering ASP.NET services and instances
We'll be focusing on the
ConfigureServices method and performing registration through the
Throughout this video, We'll see the behavior of our
HelloWorldService change. We will inject the
HelloWorldService into a Razor page, and the changes will become clear as we switch between the registration types in
We'll first register our dependency as
Transient. The creation of our
HelloWorldService will occur every time our application asks for an instance. Changing our registration to Scoped will create a single instance for each new web request. Finally, registering a dependency as a
Singleton will limit our
HelloWorldService to a single instance for the duration of our application's run.
By changing the registration of our dependencies, we can dramatically alter the behavior in our ASP.NET application.