Registers and reviews .NET dependency-injection services and lifetimes on IServiceCollection. Covers singleton/scoped/transient choices, feature extensions, assembly scanning with Scrutor, and service-graph validation.
Ships in dotnet-advanced. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Register a service in the composition that manages its lifetime, grouped with the capability it belongs to.
IServiceCollection registration.Group the registration in a feature extension method that returns IServiceCollection for fluent chaining; do not scatter AddX calls across the composition root.
public static class EmailServiceCollectionExtensions
{
extension(IServiceCollection services)
{
public IServiceCollection AddEmailSenders()
{
services.AddSingleton<IEmailSender, SmtpEmailSender>();
return services;
}
}
}
Never inject a scoped service into a singleton, and never make a service singleton when it stores per-operation mutable state.
Register the concrete type when no consumer needs an abstraction; register interface + implementation when a consumer depends on an intentional seam.
Register a hosted service separately from its ordinary contract when both resolve to the same process-owned instance.
Use Scrutor's Scan to register many types by convention, not by listing each, when they share a marker interface or naming pattern.
services.Scan(scan => scan
.FromAssemblyOf<SmtpEmailSender>()
.AddClasses(classes => classes.AssignableTo<IValidator>())
.AsImplementedInterfaces()
.WithTransientLifetime());
Move every registration group — a set of related AddX calls or a Scrutor Scan — into its capability's extension method, and let the host composition root call only those methods.
The host configuration contains no registration detail.
Declare the extension with a C# 14 extension block; the IServiceCollection receiver is named once for the whole capability:
public static class EmailServiceCollectionExtensions
{
extension(IServiceCollection services)
{
public IServiceCollection AddEmailSenders()
{
services.AddSingleton<IEmailTemplateStore, FileEmailTemplateStore>();
services.Scan(scan => scan
.FromAssemblyOf<SmtpEmailSender>()
.AddClasses(classes => classes.AssignableTo<IEmailSender>())
.AsImplementedInterfaces()
.WithSingletonLifetime());
return services;
}
}
}
The composition root then reads as a flat list of capabilities, with no AddX or Scan detail inlined:
services.AddEmailSenders();
Build the host through its normal entry point and resolve the changed service through the owning path or a focused composition test.
Never construct a second ServiceProvider in production registration code.
AddX group or Scrutor Scan is inlined where the host is configured.| Pitfall | Correct approach |
|---|---|
| Scoped service injected into a singleton | Make the consumer scoped, or pass a factory / IServiceScopeFactory. |
| Singleton storing per-request mutable state | Use scoped or transient. |
Scan not found | The Scrutor package is not referenced in the project. |
A second new ServiceProvider() to resolve something | Resolve through the real host or a composition test. |
AddX group or Scrutor Scan inlined where the host is configured | Wrap it in a capability extension, for example AddEmailSenders, and call it from the root. |
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
dotnet-di, service-registration, scrutor, lifetime-management
/dotnet-advanced:configuring-dotnet-dependency-injectionfrom dotnet-advanced
npx claudepluginhub nice3point/revit-skills --plugin dotnet-advanced5 skills in this plugin
/binding-and-validating-optionsBind a configuration section to a typed options class and validate it at startup with the .NET options pattern. USE FOR: adding an options type, binding it from configuration, applying DataAnnotations or custom validation, and failing fast on invalid configuration with ValidateOnStart. DO NOT USE FOR: general host composition and the order of builder extensions (use configuring-dotnet-hosting).
/configuring-dotnet-hostingConfigure a .NET application host and its feature-registration extensions on IHostApplicationBuilder. USE FOR: composing HostApplicationBuilder/WebApplicationBuilder, writing IHostApplicationBuilder extension methods, registering shared service defaults, and host startup and lifecycle. DO NOT USE FOR: choosing a service lifetime or a single registration (use configuring-dotnet-dependency-injection), or binding and validating an options section (use binding-and-validating-options).
/designing-dotnet-typesChoose the right kind of .NET type for new behavior — static class, extension method, injected service, hosted service, options type, record, or interface. USE FOR: deciding how to shape a new unit of behavior or data before writing it, or reviewing that an existing type has the right shape for its dependencies and lifecycle. DO NOT USE FOR: registering a type or choosing its DI lifetime (use configuring-dotnet-dependency-injection).
/dotnet-source-generated-loggingWrite .NET logs with the LoggerMessage source generator for ILogger calls. USE FOR: adding or reviewing log statements built from [LoggerMessage] partial methods — message templates, log levels, event ids, exception logging, and logging scopes.
Other plugins' skills for the same job