Skip to content

MatthewKing/WindowsFormsGenericHost

Repository files navigation

Windows Forms Generic Host

WindowsFormsGenericHost is a simple library that allows you to use the .NET Generic Host model with Windows Forms applications, on both .NET Core and .NET Framework.

Credit and inspiration

This project was inspired by Alex Oswald's WindowsFormsLifetime project. It was released soon after his project, with the aims of adding support for ApplicationContext, and having a slightly different API and implementation. It also borrows heavily from Microsoft.Extensions.Hosting's ConsoleLifetime

I'd recommend using WindowsFormsLifetime instead of this project, as it was the original and is more actively maintained. However, if this project suits your use case more, then feel free to use this one.

Quickstart

Set up your Program.cs in a similar manner to this:

static class Program
{
    public static void Main(string[] args)
    {
        using var host = Host.CreateDefaultBuilder()
            .ConfigureServices(ConfigureServices)
            .UseWindowsFormsLifetime<MainForm>()
            .Build();

        host.Run();
    }

    private static void ConfigureServices(IServiceCollection services)
    {
        services.AddForms();

        services.AddYourOtherServicesHere();
    }
}

More examples

Check out the samples

Installation

Just grab it from NuGet

PM> Install-Package WindowsFormsGenericHost
$ dotnet add package WindowsFormsGenericHost

License and copyright

Copyright Matthew King. Distributed under the MIT License. Refer to license.txt for more information.

About

Adds Windows Forms support to the .NET Generic Host.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published