Aspnetcore: Blazor Template Similar to JavaScriptServices

Created on 19 Jun 2019  路  11Comments  路  Source: dotnet/aspnetcore

I'm looking to convert an Angular/JavaScriptServices App to Blazor.

When I look at the template structure, is it possible to do Server Side Blazor with MVC endpoints?

My current App is a single App Service with Angular calling into MVC endpoints. All within a single App Service.

What would be the equivalent Blazor setup? I understand "Blazor (ASP.NET Core hosted)" but isn't that just a client side Blazor project with a corresponding web API project?

I want both Blazor and my MVC endpoints that Blazor is hitting in the same project.

area-blazor question

All 11 comments

Thanks for contacting us, @aherrick.
For Server-Side Blazor application, you don't even need to expose APIs. If, of course, you have them, you can simply call into them, as your C# code is going to execute on the server anyway.

The reason I want to expose APIs is so I can keep the structure the same as I can easily move between Client and Server side Blazor if needed.

Anymore thoughts here?

Well, you can always expose your APIs through controllers, but all the calls then will need to go through the web, even though you're essentially on the same server. So you'll end up making HttpClient calls all the times - even for Server hosted model. That seems like a waste of resources.

But how do I setup myself to use an API for both a Client or a Server side Blazor then?

Here is a sample app which does exactly that: https://github.com/danroth27/BlazorDualMode
Look at how the IWeatherForecastService is implemented in server and client.

This is closer to where I want to be... the problem here is it's still two different code paths for production (client) and development (server).

In development mode, how do you realistically test the HTTP/API/Controller endpoints?

Check out the WebApplicaitonFactory - that should help: https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.2#basic-tests-with-the-default-webapplicationfactory

Hey @mkArtakMSFT thanks for the help. What exactly is your solution here? do you have an example with Blazor showing this off? thanks

Actually, I take that back. The WebApplicationFactory won't help here. For Blazor specifically, we don't have a good solution at the moment. However, we do have something in development, which we hope will turn into something similar to WebApplicationFactory but for Blazor.

Thank you for contacting us. Due to no activity on this issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fayezmm picture fayezmm  路  3Comments

markrendle picture markrendle  路  3Comments

FourLeafClover picture FourLeafClover  路  3Comments

rbanks54 picture rbanks54  路  3Comments

aurokk picture aurokk  路  3Comments