AutoCtor 4.0.0
See the version list below for details.
dotnet add package AutoCtor --version 4.0.0
NuGet\Install-Package AutoCtor -Version 4.0.0
<PackageReference Include="AutoCtor" Version="4.0.0" />
<PackageVersion Include="AutoCtor" Version="4.0.0" />
<PackageReference Include="AutoCtor" />
paket add AutoCtor --version 4.0.0
#r "nuget: AutoCtor, 4.0.0"
#:package AutoCtor@4.0.0
#addin nuget:?package=AutoCtor&version=4.0.0
#tool nuget:?package=AutoCtor&version=4.0.0
AutoCtor
AutoCtor is a Roslyn Source Generator that will automatically create a constructor for your class for use with constructor Dependency Injection.
How to Use
- Make the class
partial - Add
[AutoConstruct] - Remove the constructor
+[AutoConstruct]
public partial class AService
{
private readonly IDataContext _dataContext;
private readonly IDataService _dataService;
private readonly IExternalService _externalService;
private readonly ICacheService _cacheService;
private readonly ICacheProvider _cacheProvider;
private readonly IUserService _userService;
- public AService(
- IDataContext dataContext,
- IDataService dataService,
- IExternalService externalService,
- ICacheService cacheService,
- ICacheProvider cacheProvider,
- IUserService userService
- )
- {
- _dataContext = dataContext;
- _dataService = dataService;
- _externalService = externalService;
- _cacheService = cacheService;
- _cacheProvider = cacheProvider;
- _userService = userService;
- }
}
Service Providers
AutoCtor can also build the container. Register services with attributes on a partial class, and the whole object graph is resolved during compilation and emitted as plain C#.
[ServiceProvider]
[Singleton<IClock, SystemClock>]
[Scoped<IUnitOfWork, UnitOfWork>]
[Transient<IReportBuilder, ReportBuilder>]
public partial class Container;
You get a real IServiceProvider with scopes, and disposal in reverse construction order. There is no reflection, no container and no registration API at run time -- every construction site is a literal new, so there is nothing for trimming or AOT to preserve.
Because the graph is decided when the compiler runs, the problems Microsoft's container finds when someone resolves a service are build errors instead: a dependency nothing is registered for, a circular dependency, a scoped service captured by a singleton.
Singletons, scoped services, transients, keyed services, open generics, IEnumerable<T> injection, factory members and IAsyncDisposable are all supported. AutoCtor adds no package dependency of its own: where Microsoft.Extensions.DependencyInjection.Abstractions is referenced the generated types implement the interfaces from it that fit, and where it is not, those interfaces are left off and every member behind them stands on its own. A provider can also fall back to another IServiceProvider for anything it does not register, which is how it sits under a host.
See the full readme for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (4)
Showing the top 4 popular GitHub repositories that depend on AutoCtor:
| Repository | Stars |
|---|---|
|
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
|
|
|
moonheart/mementomori-helper
メメントモリ MementoMori 游戏助手 Game Assistant ゲームアシスタント
|
|
|
lokinmodar/Echoglossian
FFXIV Dialogue text translator
|
|
|
Haselnussbomber/HaselTweaks
A collection of quality of life tweaks and more.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1 | 106 | 10/12/2026 |
| 4.0.0 | 158 | 10/7/2026 |
| 3.1.1 | 2,118 | 8/14/2026 |
| 3.1.0 | 2,650 | 6/17/2026 |
| 3.0.0 | 5,466 | 4/29/2026 |
| 3.0.0-rc8 | 128 | 4/28/2026 |
| 3.0.0-rc7 | 119 | 4/26/2026 |
| 3.0.0-rc6 | 138 | 4/24/2026 |
| 3.0.0-rc5 | 124 | 4/23/2026 |
| 3.0.0-rc4 | 130 | 4/23/2026 |
| 3.0.0-rc3 | 125 | 4/22/2026 |
| 3.0.0-rc2 | 118 | 4/22/2026 |
| 3.0.0-rc1 | 120 | 4/22/2026 |
| 2.12.0 | 4,311 | 2/16/2026 |
| 2.11.0 | 239 | 2/14/2026 |
| 2.10.0 | 27,535 | 11/15/2025 |
| 2.8.2 | 16,259 | 10/14/2025 |
| 2.8.1 | 28,471 | 5/26/2025 |
| 2.8.0 | 9,653 | 4/22/2025 |