warp-winforms-application-builder

Bootstraps WinForms apps with WARP's IHost-based WinFormsApplicationBuilder and DI-enabled Forms.

1|1|Updated Jun 12, 2022
One-click install
npx skills add https://github.com/KlausLoeffelmann/WinFormsDevTools --skill warp-winforms-application-builder-klausloeffelmann
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: warp-winforms-application-builder
Source: https://github.com/KlausLoeffelmann/WinFormsDevTools/tree/main/.github/skills/WARP-WinFormsApplicationBuilder
Command: npx skills add https://github.com/KlausLoeffelmann/WinFormsDevTools --skill warp-winforms-application-builder-klausloeffelmann

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires WarpToolkit.WinForms.AppServices.

What problem does it solve? Classic WinForms apps built on Application.Run(new Form1()) cannot use the .NET Generic Host's dependency injection, configuration, and logging, and DI conflicts with the WinForms Designer's requirement for parameterless constructors. This Skill guides retrofitting or bootstrapping a WinForms app with WARP's WinFormsApplication / WinFormsApplicationBuilder so Forms and UserControls act as IServiceProvider façades for designer-droppable components. ## Core Features & Use Cases - Canonical bootstrap pattern: Replace Program.cs with WinFormsApplication.CreateBuilder(args), UseStartupForm<TForm>(), and fluent Use* configuration methods. - Form preparation recipe: Implement the two-constructor pattern (parameterless Designer ctor plus DI ctor chaining : this()), explicit IServiceProvider implementation, and the nested DeferredServiceProvider wrapper. - Deferral guidance: Avoid the "too early" trap by deferring service resolution to ISupportInitialize.EndInit or OnLoad, with a debugging checklist for common DI failures. - Use Case: Migrate an existing LOB WinForms application to hosted DI so WebView2-based ChatView and AIServicesComponent can be resolved from the service provider without breaking the Designer. ## Quick Start Ask the AI to retrofit your existing WinForms Program.cs and MainForm to use WARP's WinFormsApplicationBuilder with the two-constructor DI pattern.

Frequently Asked Questions about warp-winforms-application-builder

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add dependency injection to a WinForms application?▼

Replace Application.Run(new Form1()) with WinFormsApplication.CreateBuilder(args), call UseStartupForm<TForm>() to register the startup form as scoped, register services on builder.Services, then call Build().Run(). This brings the .NET Generic Host's DI, configuration, and logging to WinForms.

How do I make a WinForms Form work with both DI and the Designer?▼

Keep the parameterless constructor for the Designer and add a parameterized constructor Form(IServiceProvider sp) : this() that wraps the provider in a DeferredServiceProvider. Implement IServiceProvider explicitly so the Designer-emitted SetServiceProvider(this) calls resolve correctly.

Why does my component get a NullReferenceException when resolving services during InitializeComponent?▼

The Form's _serviceProvider field is only assigned after the parameterless constructor and InitializeComponent finish, so synchronous GetService calls inside SetServiceProvider fail. Defer service lookups to ISupportInitialize.EndInit or the Form's OnLoad.

Does WARP WinFormsApplicationBuilder support WebView2-based chat components?▼

Yes, the ChatView component in WarpToolkit.WinForms.Chat is built on WebView2 and is acquired from the service provider, which requires the hosted-app model. Register it with builder.Services.TryAddScoped<ChatView>() and resolve it in OnLoad.

Can I use WinFormsApplicationBuilder with a VB.NET WinForms project?▼

VB projects do not get a Program.vb, so use the VB Application Framework via ApplicationEvents.vb for ApplyApplicationDefaults and the WARP-provided startup integration for DI registration. The warp-app-services skill covers the VB recipe.

What are common mistakes when retrofitting WinForms apps to hosted DI?▼

Common mistakes include calling InitializeComponent from both constructors, assigning the real provider directly instead of wrapping it in DeferredServiceProvider, resolving services inside SetServiceProvider, and storing IServiceProvider in a static field. The skill's anti-patterns section and debugging checklist cover each failure mode.