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 - 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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Basic Blazor components4m 46s
-
(Locked)
Routing in Blazor4m 59s
-
(Locked)
Dependency injection and services with Blazor8m 42s
-
(Locked)
Blazor component life cycle8m 3s
-
(Locked)
Data binding and events with Blazor3m 47s
-
(Locked)
Binding between Blazor components3m 22s
-
(Locked)
Child content in a Blazor component4m 21s
-
(Locked)
Blazor layouts3m 38s
-
(Locked)
Challenge: Respond to an event in a subcomponent1m 1s
-
(Locked)
Solution: Respond to an event in a subcomponent1m 57s
-
-
-
-
-
-