SourceGen.Ioc.Cli
1.0.3-alpha
dotnet tool install --global SourceGen.Ioc.Cli --version 1.0.3-alpha
dotnet new tool-manifest
dotnet tool install --local SourceGen.Ioc.Cli --version 1.0.3-alpha
#tool dotnet:?package=SourceGen.Ioc.Cli&version=1.0.3-alpha&prerelease
nuke :add-package SourceGen.Ioc.Cli --version 1.0.3-alpha
SourceGen.Ioc.Cli
A command-line tool that helps you quickly add [IoCRegister] attributes to existing classes or generate [IocRegisterFor] annotations in your project.
Installation
dotnet tool install -g SourceGen.Ioc.Cli
Commands
Add Attribute Command
Add [IoCRegister] attribute to classes matching the specified criteria.
sourcegen-ioc add [options]
Options
| Option | Description | Default |
|---|---|---|
-t, --target |
Target directory or file | Current directory |
-f, --file-pattern |
File pattern to filter files | *.cs |
-s, --search-sub-directories |
Search subdirectories | false |
-cn, --class-name-regex |
Regex pattern to match class names | null |
--full-regex |
Full regex pattern to match file content | null |
--attribute-name |
Name of the attribute to add | IocRegister |
-m, --max-apply |
Maximum matches to apply (0 = unlimited) | 0 |
-n, --dry-run |
Preview changes without modifying files | false |
-v, --verbose |
Enable detailed logging | false |
--log |
Logging file path | "" |
Examples
# Preview changes first (dry-run)
sourcegen-ioc add -t ./src/MyProject -s -cn ".*Service" -n -v
# Apply changes
sourcegen-ioc add -t ./src/MyProject -s -cn ".*Service"
# Add attributes to Handler classes
sourcegen-ioc add -t ./src/Handlers -s -cn ".*Handler"
Generate IocRegisterFor Command
Collect classes matching the specified criteria and generate a file with [IocRegisterFor] assembly attributes.
sourcegen-ioc generate ioc-for [options]
Options
| Option | Description | Default |
|---|---|---|
-o, --output-path |
Output file path (required) | N/A |
-t, --target |
Target directory or file | Current directory |
-f, --file-pattern |
File pattern to filter files | *.cs |
-s, --search-sub-directories |
Search subdirectories | false |
-cn, --class-name-regex |
Regex pattern to match class names (required) | N/A |
-m, --max-apply |
Maximum matches to apply (0 = unlimited) | 0 |
-ig, --is-generic-attribute |
Use generic attribute syntax | false |
-n, --dry-run |
Preview without creating file | false |
-v, --verbose |
Enable detailed logging | false |
--log |
Logging file path | "" |
Examples
# Generate IocRegisterFor for all Handler classes
sourcegen-ioc generate ioc-for -o ./Generated/Handlers.g.cs -t ./src -s -cn ".*Handler"
# Use generic attribute syntax
sourcegen-ioc generate ioc-for -o ./Generated/Services.g.cs -cn ".*Service" -ig
# Preview output (dry-run)
sourcegen-ioc generate ioc-for -o ./output.cs -cn ".*Repository" -n -v
Output Format
The command generates a file like:
// <auto-generated />
using SourceGen.Ioc;
[assembly: IocRegisterFor(typeof(MyApp.Services.UserService))]
[assembly: IocRegisterFor(typeof(MyApp.Services.OrderService))]
With -ig flag:
// <auto-generated />
using SourceGen.Ioc;
[assembly: IocRegisterFor<MyApp.Services.UserService>]
[assembly: IocRegisterFor<MyApp.Services.OrderService>]
Generate IocRegisterDefaults Command
Collect classes and generate a file with [IocRegisterDefaults] assembly attributes, grouping implementations by their base type/interface.
sourcegen-ioc generate ioc-defaults [options]
Options
| Option | Description | Default |
|---|---|---|
-o, --output-path |
Output file path (required) | N/A |
-t, --target |
Target directory or file | Current directory |
-f, --file-pattern |
File pattern to filter files | *.cs |
-s, --search-sub-directories |
Search subdirectories | false |
-cn, --class-name-regex |
Regex pattern to match class names (required) | N/A |
-b, --base-type-regex |
Regex pattern to match interface/base class (required) | N/A |
-m, --max-apply |
Maximum matches to apply (0 = unlimited) | 0 |
-ig, --is-generic-attribute |
Use generic attribute syntax | false |
-l, --lifetime |
Service lifetime: Singleton, Scoped, Transient |
Transient |
-n, --dry-run |
Preview without creating file | false |
-v, --verbose |
Enable detailed logging | false |
--log |
Logging file path | "" |
-cn and -b options must be specified together.
Examples
# Generate IocRegisterDefaults for Handler classes implementing IHandler
sourcegen-ioc generate ioc-defaults -o ./Generated/Handlers.g.cs -t ./src -s -cn ".*Handler" -b "IHandler"
# Use generic attribute syntax
sourcegen-ioc generate ioc-defaults -o ./Generated/Services.g.cs -cn ".*Service" -b "I.*Service" -ig
# Specify lifetime
sourcegen-ioc generate ioc-defaults -o ./Generated/Handlers.g.cs -cn ".*Handler" -b "IHandler" -l Singleton
# Preview output (dry-run)
sourcegen-ioc generate ioc-defaults -o ./output.cs -cn ".*Repository" -b "IRepository" -n -v
Output Format
The command generates a file like:
// <auto-generated />
using SourceGen.Ioc;
using Microsoft.Extensions.DependencyInjection;
[assembly: IocRegisterDefaults(typeof(IHandler), ServiceLifetime.Transient, ImplementationTypes = [typeof(MyApp.Handlers.CommandHandler), typeof(MyApp.Handlers.QueryHandler)])]
With -ig flag:
// <auto-generated />
using SourceGen.Ioc;
using Microsoft.Extensions.DependencyInjection;
[assembly: IocRegisterDefaults<IHandler>(ServiceLifetime.Transient, ImplementationTypes = [typeof(MyApp.Handlers.CommandHandler), typeof(MyApp.Handlers.QueryHandler)])]
CLI Schema Command
Output CLI schema in JSON format for LLM AI.
sourcegen-ioc cli-schema [options]
Options
| Option | Description | Default |
|---|---|---|
-c, --command |
Command name | null (all) |
-t, --target |
Target file/folder to write schema | null (stdout) |
-n, --dry-run |
Dry run | false |
-v, --verbose |
Enable detailed logging | false |
--log |
Logging file path | "" |
Related Packages
- SourceGen.Ioc - The source generator package that processes
[IoCRegister]and[IocRegisterFor]attributes
Documentation
For complete documentation, see the documentation site.
License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.3-alpha | 34 | 3/1/2026 |
| 1.0.1-alpha | 37 | 3/1/2026 |
| 1.0.0-alpha | 39 | 3/1/2026 |