{"id":20366825,"url":"https://github.com/distantcam/autoctor","last_synced_at":"2026-04-27T00:02:08.588Z","repository":{"id":44336526,"uuid":"512087796","full_name":"distantcam/AutoCtor","owner":"distantcam","description":"A Roslyn source generator for creating constructors.","archived":false,"fork":false,"pushed_at":"2026-04-11T23:57:48.000Z","size":1152,"stargazers_count":110,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-04-12T01:22:32.278Z","etag":null,"topics":["csharp","csharp-sourcegenerator","dotnet","roslyn","source-generator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/distantcam.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"distantcam"}},"created_at":"2022-07-09T03:56:12.000Z","updated_at":"2026-04-11T23:57:50.000Z","dependencies_parsed_at":"2023-12-09T01:37:13.408Z","dependency_job_id":"492dab3f-4972-4217-bdc9-68aa75561867","html_url":"https://github.com/distantcam/AutoCtor","commit_stats":{"total_commits":56,"total_committers":3,"mean_commits":"18.666666666666668","dds":0.375,"last_synced_commit":"69360b61c80d6898ea156a7ae9837beeaa5502c7"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/distantcam/AutoCtor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distantcam%2FAutoCtor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distantcam%2FAutoCtor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distantcam%2FAutoCtor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distantcam%2FAutoCtor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/distantcam","download_url":"https://codeload.github.com/distantcam/AutoCtor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distantcam%2FAutoCtor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32161325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T17:06:48.269Z","status":"ssl_error","status_checked_at":"2026-04-22T17:06:19.037Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-sourcegenerator","dotnet","roslyn","source-generator"],"created_at":"2024-11-15T00:27:17.477Z","updated_at":"2026-04-23T01:00:48.811Z","avatar_url":"https://github.com/distantcam.png","language":"C#","readme":"\u003c!--\nGENERATED FILE - DO NOT EDIT\nThis file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).\nSource File: /readme.source.md\nTo change this file edit the source file and then run MarkdownSnippets.\n--\u003e\n\n# AutoCtor\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/distantcam/autoctor/build.yml)](https://github.com/distantcam/AutoCtor/actions/workflows/build.yml)\n[![NuGet Status](https://img.shields.io/nuget/v/AutoCtor.svg)](https://www.nuget.org/packages/AutoCtor/)\n[![Nuget Downloads](https://img.shields.io/nuget/dt/autoctor.svg)](https://www.nuget.org/packages/AutoCtor/)\n\n\nAutoCtor is a Roslyn Source Generator that will automatically create a constructor for your class for use with constructor Dependency Injection.\n\n```diff\n+[AutoConstruct]\npublic partial class AService\n{\n    private readonly IDataContext _dataContext;\n    private readonly IDataService _dataService;\n    private readonly IExternalService _externalService;\n    private readonly ICacheService _cacheService;\n    private readonly ICacheProvider _cacheProvider;\n    private readonly IUserService _userService;\n\n-    public AService(\n-        IDataContext dataContext,\n-        IDataService dataService,\n-        IExternalService externalService,\n-        ICacheService cacheService,\n-        ICacheProvider cacheProvider,\n-        IUserService userService\n-    )\n-    {\n-        _dataContext = dataContext;\n-        _dataService = dataService;\n-        _externalService = externalService;\n-        _cacheService = cacheService;\n-        _cacheProvider = cacheProvider;\n-        _userService = userService;\n-    }\n}\n```\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=distantcam/autoctor\u0026type=date\u0026legend=top-left)](https://www.star-history.com/#distantcam/autoctor\u0026type=date\u0026legend=top-left)\n\n\u003ca id='toc'\u003e\u003c/a\u003e\n\u003c!-- toc --\u003e\n## Contents\n\n  * [NuGet packages](#nuget-packages)\n  * [Examples](#examples)\n    * [Basic](#basic)\n    * [Inherited](#inherited)\n    * [Properties](#properties)\n  * [Post Constructor Initialization](#post-constructor-initialization)\n    * [Extra Parameters](#extra-parameters)\n    * [`out`/`ref` Parameters](#outref-parameters)\n    * [Optional Parameters](#optional-parameters)\n  * [Argument Guards](#argument-guards)\n  * [Keyed Services](#keyed-services)\n  * [Other](#other)\n    * [Embedding The Attributes](#embedding-the-attributes)\n    * [Keeping Attributes In Code](#keeping-attributes-in-code)\n  * [Stats](#stats)\u003c!-- endToc --\u003e\n\n## NuGet packages\n\nhttps://nuget.org/packages/AutoCtor/\n\n## Examples\n\n### Basic\n\n\u003c!-- snippet: Basic --\u003e\n\u003ca id='snippet-Basic'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct]\npublic partial class Basic\n{\n    private readonly IService _service;\n    private readonly IList\u003cstring\u003e _list = new List\u003cstring\u003e();\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Basic.cs#L6-L15' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Basic' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: Basic.cs#Basic.g.verified.cs --\u003e\n\u003ca id='snippet-Basic.cs#Basic.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: Basic.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class Basic\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic Basic(global::IService service)\n\t{\n\t\tthis._service = service;\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Basic.cs%23Basic.g.verified.cs#L1-L18' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Basic.cs#Basic.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n### Inherited\n\n\u003c!-- snippet: Inherited --\u003e\n\u003ca id='snippet-Inherited'\u003e\u003c/a\u003e\n```cs\npublic abstract class BaseClass\n{\n    protected IAnotherService _anotherService;\n\n    public BaseClass(IAnotherService anotherService)\n    {\n        _anotherService = anotherService;\n    }\n}\n\n[AutoConstruct]\npublic partial class Inherited : BaseClass\n{\n    private readonly IService _service;\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Inherited.cs#L6-L24' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Inherited' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: Inherited.cs#Inherited.g.verified.cs --\u003e\n\u003ca id='snippet-Inherited.cs#Inherited.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: Inherited.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class Inherited\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic Inherited(\n\t\tglobal::IAnotherService anotherService,\n\t\tglobal::IService service\n\t) : base(anotherService)\n\t{\n\t\tthis._service = service;\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Inherited.cs%23Inherited.g.verified.cs#L1-L21' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Inherited.cs#Inherited.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n### Properties\n\n\u003c!-- snippet: Properties --\u003e\n\u003ca id='snippet-Properties'\u003e\u003c/a\u003e\n```cs\n// AutoCtor will initialize these\npublic string GetProperty { get; }\nprotected string ProtectedProperty { get; }\npublic string InitProperty { get; init; }\npublic required string RequiredProperty { get; set; }\n\n// AutoCtor will ignore these\npublic string InitializerProperty { get; } = \"Constant\";\npublic string GetSetProperty { get; set; }\npublic string FixedProperty =\u003e \"Constant\";\npublic string RedirectedProperty =\u003e InitializerProperty;\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Properties.cs#L4-L18' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Properties' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: Properties.cs#Properties.g.verified.cs --\u003e\n\u003ca id='snippet-Properties.cs#Properties.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: Properties.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class Properties\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic Properties(\n\t\tstring getProperty,\n\t\tstring protectedProperty,\n\t\tstring initProperty,\n\t\tstring requiredProperty\n\t)\n\t{\n\t\tthis.GetProperty = getProperty;\n\t\tthis.ProtectedProperty = protectedProperty;\n\t\tthis.InitProperty = initProperty;\n\t\tthis.RequiredProperty = requiredProperty;\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Properties.cs%23Properties.g.verified.cs#L1-L26' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Properties.cs#Properties.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n\u003ca href='#toc' title='Back to Contents'\u003eBack to Contents\u003c/a\u003e\n## Post Constructor Initialization\n\nYou can mark a method to be called at the end of the constructor with the attribute `[AutoPostConstruct]`. This method must return void.\n\n\u003c!-- snippet: PostConstruct --\u003e\n\u003ca id='snippet-PostConstruct'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct]\npublic partial class PostConstruct\n{\n    private readonly IService _service;\n\n    [AutoPostConstruct]\n    private void Initialize()\n    {\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstruct.cs#L5-L18' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstruct' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: PostConstruct.cs#PostConstruct.g.verified.cs --\u003e\n\u003ca id='snippet-PostConstruct.cs#PostConstruct.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: PostConstruct.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class PostConstruct\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic PostConstruct(global::IService service)\n\t{\n\t\tthis._service = service;\n\t\tInitialize();\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstruct.cs%23PostConstruct.g.verified.cs#L1-L19' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstruct.cs#PostConstruct.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n### Extra Parameters\n\nPost construct methods can also take parameters. The generated constructor will include these parameters.\n\n\u003c!-- snippet: PostConstructWithParameter --\u003e\n\u003ca id='snippet-PostConstructWithParameter'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct]\npublic partial class PostConstructWithParameter\n{\n    private readonly IService _service;\n\n    [AutoPostConstruct]\n    private void Initialize(IInitializeService initialiseService)\n    {\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstructWithParameter.cs#L6-L19' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstructWithParameter' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: PostConstructWithParameter.cs#PostConstructWithParameter.g.verified.cs --\u003e\n\u003ca id='snippet-PostConstructWithParameter.cs#PostConstructWithParameter.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: PostConstructWithParameter.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class PostConstructWithParameter\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic PostConstructWithParameter(\n\t\tglobal::IService service,\n\t\tglobal::IInitializeService initialiseService\n\t)\n\t{\n\t\tthis._service = service;\n\t\tInitialize(initialiseService);\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstructWithParameter.cs%23PostConstructWithParameter.g.verified.cs#L1-L22' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstructWithParameter.cs#PostConstructWithParameter.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n### `out`/`ref` Parameters\n\nParameters marked with `out` or `ref` are set back to any fields that match the same type. This can be used to set readonly fields with more complex logic.\n\n\u003c!-- snippet: PostConstructWithOutParameter --\u003e\n\u003ca id='snippet-PostConstructWithOutParameter'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct]\npublic partial class PostConstructWithOutParameter\n{\n    private readonly IService _service;\n    private readonly IOtherService _otherService;\n\n    [AutoPostConstruct]\n    private void Initialize(IServiceProvider services, out IService service)\n    {\n        service = services.GetService\u003cIService\u003e();\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstructWithOutParameter.cs#L7-L22' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstructWithOutParameter' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: PostConstructWithOutParameter.cs#PostConstructWithOutParameter.g.verified.cs --\u003e\n\u003ca id='snippet-PostConstructWithOutParameter.cs#PostConstructWithOutParameter.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: PostConstructWithOutParameter.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class PostConstructWithOutParameter\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic PostConstructWithOutParameter(\n\t\tglobal::IOtherService otherService,\n\t\tglobal::IServiceProvider services\n\t)\n\t{\n\t\tthis._otherService = otherService;\n\t\tInitialize(services, out this._service);\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstructWithOutParameter.cs%23PostConstructWithOutParameter.g.verified.cs#L1-L22' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstructWithOutParameter.cs#PostConstructWithOutParameter.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n### Optional Parameters\n\n\u003c!-- snippet: PostConstructWithDefaultParameter --\u003e\n\u003ca id='snippet-PostConstructWithDefaultParameter'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct]\npublic partial class PostConstructWithDefaultParameter\n{\n    [AutoPostConstruct]\n    private void Initialize(Service? service = default)\n    {\n    }\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstructWithDefaultParameter.cs#L5-L16' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstructWithDefaultParameter' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: PostConstructWithDefaultParameter.cs#PostConstructWithDefaultParameter.g.verified.cs --\u003e\n\u003ca id='snippet-PostConstructWithDefaultParameter.cs#PostConstructWithDefaultParameter.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: PostConstructWithDefaultParameter.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class PostConstructWithDefaultParameter\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic PostConstructWithDefaultParameter(global::Service service = default)\n\t{\n\t\tInitialize(service);\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/PostConstructWithDefaultParameter.cs%23PostConstructWithDefaultParameter.g.verified.cs#L1-L18' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-PostConstructWithDefaultParameter.cs#PostConstructWithDefaultParameter.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n\u003ca href='#toc' title='Back to Contents'\u003eBack to Contents\u003c/a\u003e\n## Argument Guards\n\nNull guards for the arguments to the constructor can be added in 2 ways.\n\nIn your project you can add a `AutoCtorGuards` property.\n\n```xml\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n  \u003cPropertyGroup\u003e\n    \u003cAutoCtorGuards\u003etrue\u003c/AutoCtorGuards\u003e\n  \u003c/PropertyGroup\u003e\n\n\u003c/Project\u003e\n```\n\n**OR**\n\nIn each `AutoConstruct` attribute you can add a setting to enable/disable guards.\n\n\u003c!-- snippet: Guarded --\u003e\n\u003ca id='snippet-Guarded'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct(GuardSetting.Enabled)]\npublic partial class Guarded\n{\n    private readonly IService _service;\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Guarded.cs#L5-L13' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Guarded' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: Guarded.cs#Guarded.g.verified.cs --\u003e\n\u003ca id='snippet-Guarded.cs#Guarded.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: Guarded.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class Guarded\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic Guarded(global::IService service)\n\t{\n\t\tthis._service = service ?? throw new global::System.ArgumentNullException(\"service\");\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Guarded.cs%23Guarded.g.verified.cs#L1-L18' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Guarded.cs#Guarded.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n\u003ca href='#toc' title='Back to Contents'\u003eBack to Contents\u003c/a\u003e\n## Keyed Services\n\nWhen using `Microsoft.Extensions.DependencyInjection` you can mark fields and properties with `[AutoKeyedService]` and it will be included in the constructor.\n\n\u003c!-- snippet: Keyed --\u003e\n\u003ca id='snippet-Keyed'\u003e\u003c/a\u003e\n```cs\n[AutoConstruct]\npublic partial class Keyed\n{\n    [AutoKeyedService(\"key\")]\n    private readonly IService _keyedService;\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Keyed.cs#L5-L14' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Keyed' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: Keyed.cs#Keyed.g.verified.cs --\u003e\n\u003ca id='snippet-Keyed.cs#Keyed.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: Keyed.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\npartial class Keyed\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\tpublic Keyed(\n\t\t[global::Microsoft.Extensions.DependencyInjection.FromKeyedServices(\"key\")] global::IService keyedService\n\t)\n\t{\n\t\tthis._keyedService = keyedService;\n\t}\n}\n```\n\u003csup\u003e\u003ca href='/src/Tests/ReadmeExamples/Keyed.cs%23Keyed.g.verified.cs#L1-L20' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-Keyed.cs#Keyed.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n\u003ca href='#toc' title='Back to Contents'\u003eBack to Contents\u003c/a\u003e\n## Other\n\n### Embedding The Attributes\n\nBy default, the `[AutoConstruct]` attributes referenced in your project are contained in an external dll. It is also possible to embed the attributes directly in your project. To do this, you must do two things:\n\n1. Define the constant `AUTOCTOR_EMBED_ATTRIBUTES`. This ensures the attributes are embedded in your project.\n2. Add `compile` to the list of excluded assets in your `\u003cPackageReference\u003e` element. This ensures the attributes in your project are referenced, instead of the _AutoCtor.Attributes.dll_ library.\n\nYour project file should look like this:\n\n```xml\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n  \u003cPropertyGroup\u003e\n    \u003c!--  Define the MSBuild constant    --\u003e\n    \u003cDefineConstants\u003e$(DefineConstants);AUTOCTOR_EMBED_ATTRIBUTES\u003c/DefineConstants\u003e\n  \u003c/PropertyGroup\u003e\n\n  \u003c!-- Add the package --\u003e\n  \u003cPackageReference Include=\"AutoCtor\"\n                    PrivateAssets=\"all\"\n                    ExcludeAssets=\"compile;runtime\" /\u003e\n  \u003c!--                             ☝ Add compile to the list of excluded assets. --\u003e\n\n\u003c/Project\u003e\n```\n\n\u003cdetails\u003e\u003csummary\u003eWhat gets generated\u003c/summary\u003e\n\n\u003c!-- snippet: GeneratedAttributeTests.cs#AutoConstructAttribute.g.verified.cs --\u003e\n\u003ca id='snippet-GeneratedAttributeTests.cs#AutoConstructAttribute.g.verified.cs'\u003e\u003c/a\u003e\n```cs\n//HintName: AutoConstructAttribute.g.cs\n//------------------------------------------------------------------------------\n// \u003cauto-generated\u003e\n//     This code was generated by https://github.com/distantcam/AutoCtor\n// \u003c/auto-generated\u003e\n//------------------------------------------------------------------------------\n\n#if AUTOCTOR_EMBED_ATTRIBUTES\nnamespace AutoCtor\n{\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\tinternal enum GuardSetting\n\t{\n\t\tDefault,\n\t\tDisabled,\n\t\tEnabled\n\t}\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\t[global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]\n\tinternal sealed class AutoConstructAttribute : global::System.Attribute\n\t{\n\t\tpublic AutoConstructAttribute(GuardSetting guard = GuardSetting.Default)\n\t\t{\n\t\t}\n\t}\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\t[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]\n\tinternal sealed class AutoPostConstructAttribute : global::System.Attribute\n\t{\n\t}\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\t[global::System.AttributeUsage(global::System.AttributeTargets.Field | global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]\n\tinternal sealed class AutoConstructIgnoreAttribute : global::System.Attribute\n\t{\n\t}\n\t[global::System.Runtime.CompilerServices.CompilerGenerated]\n\t[global::System.CodeDom.Compiler.GeneratedCode(\"AutoCtor\", \"0.0.0.0\")]\n\t[global::System.Diagnostics.DebuggerNonUserCode]\n\t[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]\n\t[global::System.AttributeUsage(global::System.AttributeTargets.Field | global::System.AttributeTargets.Property | global::System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]\n\tinternal sealed class AutoKeyedServiceAttribute : global::System.Attribute\n\t{\n\t\tpublic object Key { get; }\n\t\tpublic AutoKeyedServiceAttribute(object key) =\u003e Key = key;\n\t}\n}\n#endif\n```\n\u003csup\u003e\u003ca href='/src/Tests/GeneratedAttributeTests.cs%23AutoConstructAttribute.g.verified.cs#L1-L57' title='Snippet source file'\u003esnippet source\u003c/a\u003e | \u003ca href='#snippet-GeneratedAttributeTests.cs#AutoConstructAttribute.g.verified.cs' title='Start of snippet'\u003eanchor\u003c/a\u003e\u003c/sup\u003e\n\u003c!-- endSnippet --\u003e\n\n\u003c/details\u003e\n\n### Keeping Attributes In Code\n\nThe `[AutoConstruct]` attributes are decorated with the `[Conditional]` attribute, so their usage will not appear in the build output of your project. If you use reflection at runtime you will not find the `[AutoConstruct]` attributes.\n\nIf you wish to preserve these attributes in the build output, add the define constant `AUTOCTOR_USAGES`.\n\n```xml\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n  \u003cPropertyGroup\u003e\n    \u003c!--  Define the MSBuild constant    --\u003e\n    \u003cDefineConstants\u003e$(DefineConstants);AUTOCTOR_USAGES\u003c/DefineConstants\u003e\n  \u003c/PropertyGroup\u003e\n\n\u003c/Project\u003e\n```\n\n\u003ca href='#toc' title='Back to Contents'\u003eBack to Contents\u003c/a\u003e\n## Stats\n\n![Alt](https://repobeats.axiom.co/api/embed/8d02b2c004a5f958b4365abad3d4d1882dca200f.svg \"Repobeats analytics image\")\n","funding_links":["https://github.com/sponsors/distantcam"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistantcam%2Fautoctor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdistantcam%2Fautoctor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistantcam%2Fautoctor/lists"}