How to host .net6 asp.net api into .net6 wpf

shusong lu 1 Reputation point
2022-01-08T18:15:58.127+00:00

Here's what I did in .net5, copying the Startup.cs and appsettings.json of the WebApi project.

using System.Windows;

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace WpfApp
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

        Host.CreateDefaultBuilder()
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            }).Build().RunAsync();
    }
}

}

But in .net6, I don't know how to do it.

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.