datapool
datapool

Reputation: 243

Blazor + MAUI: How to use .net api controllers from Blazor server/.net app in MAUI desktop app?

I want to transfer an existing Blazor Server app to a MAUI Blazor Desktop application.

However, I am currently not able to transfer the web api controllers which are started with the blazor server app in the maui app.

The program.cs uses the

app.MapControllers();

to ensure the web api controller endpoints are available from the blazor server app.

Is it possible to also transfer the .net6 web api controllers from the Blazor Server over to the MAUI app? If so, how to start the controllers in the MAUI app startup?

Thanks for any suggestion on this topic.

Upvotes: 1

Views: 2344

Answers (1)

Jan Joneš
Jan Joneš

Reputation: 938

Usual setup is to have a server hosted separately and let the MAUI app access its APIs to fetch data. During development, you have to of course start both of them (the server and the app). Official example: .NET Podcasts.

If you don't want the separate server, you don't have to use API Controllers. Simply access the data directly, it will work in both Blazor Server and MAUI.

Upvotes: 0

Related Questions