From the course: Blazor: Getting Started

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Dependency injection and services with Blazor

Dependency injection and services with Blazor - Blazor Tutorial

From the course: Blazor: Getting Started

Dependency injection and services with Blazor

- [Instructor] We've seen what it looks like to inject the data service into our components so far. But beyond that, it's a little bit magic happens here, and the indicated class was loaded and did what was requested. Dependency injection in Blazor is not substantively different from DI anywhere else. The main goal is to have a decoupling between logical actors like business logic, fetching data from the web and displaying something. Blazor was designed with dependency injection in mind, from the very beginning. It is an integral part of building an application in Blazor. We've already seen the inject keyword in our component and that we can call up a service that way, but let's look a little bit more at how that service was set up. We'll start in our client's Program dot cs. Here on lines 17 and 18, we see the service configuration. There's an AddTransient for the httpClient and an AddSingleton for the DataService.…

Contents