conficient / BlazorTemplater

A library that generates HTML (e.g. for emails) from Razor Components
Apache License 2.0
146 stars 16 forks source link

Injecting NavigationManager #37

Closed edimoldovan closed 1 year ago

edimoldovan commented 1 year ago

Hi,

Trying to render a component where @inject NavigationManager SiteNavigationManager is used to inject the Navigation manager, how should I make this work with BlazorTemplater?

Thank you, ed

conficient commented 1 year ago

The use-cases for BlazorTemplater don't really make sense to have a NavigationManager as they are rendering HTML only. If it's not removable then you might try creating an instance of it directly in your service container using a subclass.

See https://stackoverflow.com/questions/64466099/how-to-inject-navigationmanager-in-bunit-blazor-component-unit-test for an example.

You would add the instance thus:

services.AddSingleton<NavigationManager, TestNav>();

(very rough code, not tested!)