From wpf-dev-pack
Implements dependency injection using GenericHost in .NET console applications. Covers hosted services, background tasks, configuration, logging, service lifetimes, and anti-patterns like service locator.
npx claudepluginhub christian289/dotnet-with-claudecode --plugin wpf-dev-packThis skill uses the workspace's default tool permissions.
A guide for implementing dependency injection using GenericHost in .NET Console Application.
Generates design tokens/docs from CSS/Tailwind/styled-components codebases, audits visual consistency across 10 dimensions, detects AI slop in UI.
Records polished WebM UI demo videos of web apps using Playwright with cursor overlay, natural pacing, and three-phase scripting. Activates for demo, walkthrough, screen recording, or tutorial requests.
Delivers idiomatic Kotlin patterns for null safety, immutability, sealed classes, coroutines, Flows, extensions, DSL builders, and Gradle DSL. Use when writing, reviewing, refactoring, or designing Kotlin code.
A guide for implementing dependency injection using GenericHost in .NET Console Application.
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.*" />
</ItemGroup>
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
services.AddSingleton<IMyService, MyService>();
services.AddSingleton<App>();
})
.Build();
var app = host.Services.GetRequiredService<App>();
await app.RunAsync();
namespace MyApp;
public sealed class App(IMyService myService)
{
private readonly IMyService _myService = myService;
public async Task RunAsync()
{
await _myService.DoWorkAsync();
}
}
| Lifetime | Description | Use When |
|---|---|---|
Singleton | Single instance for entire app | Stateless services |
Scoped | Single instance per request | DbContext |
Transient | New instance per injection | Lightweight services |
var host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile("appsettings.json", optional: true);
})
.ConfigureServices((context, services) =>
{
services.Configure<AppSettings>(
context.Configuration.GetSection("AppSettings"));
services.AddSingleton<App>();
})
.Build();
public sealed class App(ILogger<App> logger)
{
public Task RunAsync()
{
logger.LogInformation("Application started");
return Task.CompletedTask;
}
}
// ❌ Bad example
public sealed class BadService(IServiceProvider provider)
{
public void DoWork()
{
var service = provider.GetRequiredService<IMyService>();
}
}
// ✅ Good example
public sealed class GoodService(IMyService myService)
{
public void DoWork() { }
}