Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (26 sloc) 1.27 KB
title subtitle
Using Blazor features

This page documents some useful features of Blazor and how to best use them from a Bolero application.

Dependency injection

Blazor provides the ability to work with the dependency injection mechanism introduced by ASP.NET Core. Learn more about it on the official documentation.

Requiring a dependency

Any Blazor component can require a dependency. This includes the Bolero ProgramComponent, as well as any Component class you create. This is done by creating a mutable property with the attribute Microsoft.AspNetCore.Components.Inject:

open Microsoft.AspNetCore.Components
open Bolero

type MyApp() =
    inherit ProgramComponent<Model, Message>()
    member val MyDependency = Unchecked.defaultof<IMyDependency> with get, set
    override this.Program =
        doSomethingWith this.MyDependency

Providing a dependency

Dependencies are injected from the client-side Startup class's ConfigureServices method:

type Startup() =

    member __.ConfigureServices(services: IServiceCollection) =
        services.AddSingleton<IMyDependency>(new MyDependency()) |> ignore
You can’t perform that action at this time.