Dependency injection (DI)
html.inject may be the most challenging API in Fun.Blazor due to its render behavior. (Even though we do not have many APIs, just a bunch of DSLs for building the DOM.) By default, every time you call it, you will get a fresh new component. So, if you want to keep some state that should not be erased by its caller, you should specify a key as its first parameter.
Another challenging thing is its internal rendering. It requires a function as its parameter, this function is 'Services -> NodeRenderFragment
. 'Services is a tuple of service types you want to inject. NodeRenderFragment is a delegate that composes the DOM tree (which can be treated as another function). By default, the DOM tree will not change unless you manually trigger it by calling hook.StateHasChanged(), or by doing things like the example below: