Just checked out the video on " Create Universal Blazor API Components for Blazor Server and WASM"
Great to see this integration!!
Couple of questions on this:
Creating a unified project with both WASM & Blazor Server I would like to centralize my UI assets into a Razor Class Library. Doing so I’m not sure how to handle the ServiceStackStateProvider as there are 2 versions for Blazor Server & Blazor WASM
public class ServiceStackStateProvider : BlazorWasmAuthenticationStateProvider
{
public ServiceStackStateProvider(BlazorWasmAuthContext context, ILogger log)
: base(context, log) { }
}
What is the recommended way of using ServiceStackStateProvider in a seperate Razor Class Library ?
I would like to reference this RCL in all my projects including MAUI Blazor. This leads to my second question. How do we use Servicestack Blazor within MAUI ? Do we use the Blazor Server or the Blazor WASM references ?
You wont be able to include both BlazorWasmAuthenticationStateProvider and BlazorServerAuthenticationStateProvider in the same library, they’re different implementations of AuthenticationStateProvider to enable authentication in each hosting model, as such the App’s custom implementations of them should be registered in your host projects Program.cs IOC as done in the project templates.
But you shouldn’t reference these classes directly, e.g. ServiceStack.Blazor’s “auth-aware” AuthBlazorComponentBase base class only references Blazor’s AuthenticationState as recommended so they never reference a specific auth implementation.
I’ve not used MAUI before, it’s something we can look at soon. Hopefully you should just be able to reference ServiceStack.Blazor which can be used directly in WASM and Blazor Server and hopefully in MAUI.
Thanks Myth. The wholly grail for me is when we can run all the platforms ( device form factors ) from within the same project using one UI. Fortunately that is coming. Currently MAUI Blazor supports all the old Xamarin Forms form factors via the BlazorWebview control but I see .NET 8 planning includes adding WASM and Blazor Server to the same project.
I saw an exciting new Blazor protype by Steve Sanderson that combines plain HTML , Blazor Server + Blazor WASM into one project for .NET 8.
Just hope that they can incorporate the authentication state with that. The SS AuthenticationStateProvider will probably have to change then to incorporate this new architecture.
Yep seen it as well. Still early days so not clear how Auth State is going to work within the new Unified rendering modes, but we should be able to support whatever they end up going with.
Yep, if they get this right I see much more broader mass appeal for Blazor. Are you aware of any framework out there that can switch seamlessly between the 3 modes ?
Thanks. Would be really awesome if they could somehow expand this idea into a cached MAUI Blazor app where instead of precompiled Blazor Views you can have a opt-in dynamically cached version of your Blazor views without reinstalling the mobile app or going through the app store again.
Don’t see that happening, self hosting Mobile Apps are only going to include a minimal .NET runtime to run the App, they’re unlikely to have Blazor’s dev time tooling that convert .razor into .cs, then a C# compiler/SDK to compile the sources. IMO best Mobile Apps will be able to do is send .blazor to an externally hosted API that builds it and returns a .dll that the App can try dynamically loading.
Maybe someone will build an interpreter, but IMO doubtful.