{"id":16567359,"url":"https://github.com/tobysmith568/di-attributes","last_synced_at":"2025-08-17T21:12:51.542Z","repository":{"id":37894720,"uuid":"410572961","full_name":"tobysmith568/di-attributes","owner":"tobysmith568","description":"Super-small and super-simple library for registering classes with the ASP.NET Core IServiceCollection using attributes.","archived":false,"fork":false,"pushed_at":"2025-08-10T18:00:47.000Z","size":192,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-10T20:17:34.248Z","etag":null,"topics":["attribute","dependency","di","injection","ioc","iservicecollection"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/DiAttributes","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tobysmith568.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2021-09-26T14:24:04.000Z","updated_at":"2025-08-10T18:00:35.000Z","dependencies_parsed_at":"2024-02-13T18:10:14.267Z","dependency_job_id":"e25d244a-47a1-4c72-9f26-ad3eb5f23f3b","html_url":"https://github.com/tobysmith568/di-attributes","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/tobysmith568/di-attributes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobysmith568%2Fdi-attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobysmith568%2Fdi-attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobysmith568%2Fdi-attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobysmith568%2Fdi-attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobysmith568","download_url":"https://codeload.github.com/tobysmith568/di-attributes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobysmith568%2Fdi-attributes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270906543,"owners_count":24665803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["attribute","dependency","di","injection","ioc","iservicecollection"],"created_at":"2024-10-11T21:06:23.126Z","updated_at":"2025-08-17T21:12:51.497Z","avatar_url":"https://github.com/tobysmith568.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DiAttributes\n\nSuper-small and super-simple library for registering classes with the ASP.NET Core `IServiceCollection` using attributes.\n\n\u003ca href=\"https://www.nuget.org/packages/DiAttributes\"\u003e\n  \u003cimg alt=\"NuGet\" src=\"https://img.shields.io/nuget/v/DiAttributes?logo=nuget\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/tobysmith568/di-attributes\"\u003e\n  \u003cimg alt=\"CodeCov\" src=\"https://codecov.io/gh/tobysmith568/di-attributes/branch/main/graph/badge.svg\"/\u003e\n\u003c/a\u003e\n\nGitHub: https://github.com/tobysmith568/di-attributes  \nNuGet: https://www.nuget.org/packages/DiAttributes\n\n## Scoped, Transient, and Singleton\n\nClasses can be registered as any of these three types of dependency via the respective attributes:\n\n```cs\nusing DiAttributes;\n\n[Scoped]\npublic class MyService\n{ ... }\n```\n\nThis is the equivalent of having the following in your `Startup.cs`:\n\n```cs\nservices.Scoped\u003cMyService\u003e();\n```\n\nYou can also pass in a type as an argument to register the class against:\n\n```cs\nusing DiAttributes;\n\npublic interface IMyService\n{ ... }\n\n[Scoped(typeof(IMyService))]\npublic class MyService : IMyService\n{ ... }\n```\n\nThis is the equivalent of having the following in your `Startup.cs`:\n\n```cs\nservices.Scoped\u003cIMyService, MyService\u003e();\n```\n\nThe use of these attributes will require you to add the following line once to your `Startup.cs` file:\n\n```cs\nservices.RegisterDiAttributes();\n```\n\n## Configuration\n\nClasses can be automatically bound to sections of your app's configuration using the `[Configuration]` attribute.\n\nIf your `appsettings.json` looks like this:\n```json\n{\n  \"Outer\": {\n    \"Inner\": {\n      \"MySetting\": \"My Value\"\n    }\n  }\n}\n```\n\nThen you can bind a class to the `Inner` object (for example) and register it with the `IServiceCollection` like this:\n```cs\nusing DiAttributes;\n\n[Configuration(\"Outer:Inner\")]\npublic class MyInnerOptions\n{\n  public string MySetting { get; set; }\n}\n```\n\nTo use this attribute you will need to pass an `ICollection` instance to the `RegisterDiAttributes` call in your `Startup.cs` file:\n```cs\nservices.RegisterDiAttributes(Configuration);\n```\n## HttpClient\n\nClasses can be registered as HttpClients using the `HttpClient` attribute.  \nAs per the [Microsoft Docs](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-6.0#typed-clients), these classes will be registered as transient.\n\n```cs\nusing DiAttributes;\n\n[HttpClient]\npublic class MyHttpClient\n{\n  public MyHttpClient(HttpClient httpClient)\n  { ... }\n}\n```\n\nThis is the equivalent of having the following in your `Startup.cs`:\n\n```cs\nservices.AddHttpClient\u003cMyHttpClient\u003e();\n```\n\nYou can also pass in a type as an argument to register the class against:\n\n```cs\npublic interface IMyHttpClient\n{ ... }\n\n[Scoped(typeof(IMyHttpClient))]\npublic class MyHttpClient : IMyHttpClient\n{\n  public MyHttpClient(HttpClient httpClient)\n  { ... }\n}\n```\n\nThis is the equivalent of having the following in your `Startup.cs`:\n\n```cs\nservices.AddHttpClient\u003cIMyHttpClient, MyHttpClient\u003e();\n```\n\n## Licence\n\nDiAttributes is licensed under the [ISC License](https://github.com/tobysmith568/di-attributes/blob/main/LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobysmith568%2Fdi-attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobysmith568%2Fdi-attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobysmith568%2Fdi-attributes/lists"}