DaaWaan
DaaWaan

Reputation: 641

Configure Blazor Server to host WebAPI

I'm planning to create an ASP.NET Core hosted Blazor WASM application but because of limited debugging experience and slower development, I'm choosing Blazor Server Application hosting a WebAPI instead to mimic the architecture of the said project type to ease switching back when .NET 5 is released. The problem is I don't know how to configure the Startup class to use WebAPI. Unfortunately, I can't find any links that demonstrate using a WebAPI in Blazor Server.

Assuming I already have my controllers added in the project, what should I modify in the ConfigureServices() and the Configure() methods of the Startup to use the controllers?

Upvotes: 0

Views: 1593

Answers (1)

DaaWaan
DaaWaan

Reputation: 641

Anyway, finally figured it out. To use controllers in Blazor Server and in any ASP.NET Core application for an API, just map the controllers in the Configure().

public void Configure(IAppplicationBuilder app, IWebHostEnvironment env)
{
    ...
    app.UseEndpoints(endpoints => 
    {
        endpoints.MapControllers();
        ...
    });
}

Upvotes: 2

Related Questions