Would LOVE to see a template for Blazor WASM

I realize it won’t be released until sometime in May (hopefully) but latest previews are getting pretty stable and really good. Is there anyway to accommodate this now, with the understanding that things may break for future release? Otherwise, I guess I’ll just have to be patient. :wink:

Best way is to follow (and hopefully help contribute to) the work of @nukedbit who has created a Blazor Template at https://github.com/nukedbit/blazor-servicestack

Can be installed with:

$ x new nukedbit/blazor-servicestack ProjectName

My template is about blazor server side.
But just yesterday i found out a few issues with my implementation. I got so excited that i got it working that i didn’t think it thoroughly.
The current integration is using IHttpContextAccessor to get the http context and then map that to ServiceStack NetCoreRequest, that would allowed to get some nice facility like ServiceStack does for ServiceStackController. This in reality while nice how is done can’t work in production, basically if everything get executed on the first request you won’t notice any issue, but when you put it in a server far away or using an iPad which behave differently in how it handles connections, the blazor app will crash because there is no HttpContext. That’s because at that point the rendering of the UI changes will happen over SignalR so there is not HttpContext.
I didn’t dig deep why it worked for me locally initially, but at this point there is nothing with this approach that could work.
For me the workaround was to keep the integrated auth between ServiceStack and MVC, but to call ServiceStack Services with the JsonServiceClient, by passing an ApiKey which i have included on the claims.

I didn’t test on blazor wasm, there you are going to probably have to implement a custom authentication state with a JWT Token, then you can call your ServiceStack Services like any spa does.

1 Like

Hi i have updated the example you can see the change on this commit.

Basically now no custom base component is needed, each component need just to have this property defined then you can await it and get the client from an extension method.

    public Task<AuthenticationState> AuthenticationState {get;set;}    

    protected override async Task OnInitializedAsync()
        var state = await AuthenticationState;
        var client = state.ToClient();
        forecasts = await client.GetAsync(new GetWeatherForecast()
            StartDate = DateTime.Now

For this to work you have to configure apikeys and the claims as in the template.
Maybe this can be helpful to someone.
Any contribution is highly accepted :slight_smile:

So is this for client side or server side?