{"id":25835968,"url":"https://github.com/revazashvili/netjection","last_synced_at":"2025-06-29T17:03:36.697Z","repository":{"id":37028571,"uuid":"473957050","full_name":"Revazashvili/Netjection","owner":"Revazashvili","description":".Net package to automatically inject attribute decorated services into IOC Container","archived":false,"fork":false,"pushed_at":"2023-03-16T16:53:11.000Z","size":121,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-29T17:03:07.587Z","etag":null,"topics":["attribute","csharp","dependency-injection","dotnet","ioc-container","scoped","singleton","transient"],"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/Revazashvili.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},"funding":{"ko_fi":"revazashvili","custom":"buymeacoffee.com/revazashvili"}},"created_at":"2022-03-25T10:03:00.000Z","updated_at":"2024-08-21T07:31:56.000Z","dependencies_parsed_at":"2025-06-29T17:03:11.106Z","dependency_job_id":null,"html_url":"https://github.com/Revazashvili/Netjection","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/Revazashvili/Netjection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FNetjection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FNetjection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FNetjection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FNetjection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Revazashvili","download_url":"https://codeload.github.com/Revazashvili/Netjection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Revazashvili%2FNetjection/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262632323,"owners_count":23340212,"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","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","csharp","dependency-injection","dotnet","ioc-container","scoped","singleton","transient"],"created_at":"2025-03-01T01:38:44.477Z","updated_at":"2025-06-29T17:03:36.675Z","avatar_url":"https://github.com/Revazashvili.png","language":"C#","funding_links":["https://ko-fi.com/revazashvili","buymeacoffee.com/revazashvili"],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"injection.png\" height=\"40px\" /\u003e Netjection\n.Net package to automatically inject attribute decorated services into IOC Container\n\n[![.NET](https://img.shields.io/badge/--512BD4?logo=.net\u0026logoColor=ffffff)](https://dotnet.microsoft.com/)\n![Nuget](https://img.shields.io/nuget/dt/Netjection?color=green)\n[![NuGet stable version](https://badgen.net/nuget/v/Netjection?color=red)](https://www.nuget.org/packages/Netjection)\n[![GitHub license](https://badgen.net/github/license/Revazashvili/Netjection?color=yellow)](https://github.com/Revazashvili/Netjection/blob/main/LICENSE)\n\n\n\n## Give a Star! :star:\nIf you like or are using this project please give it a star. Thanks!\n\n## Installing\nUsing dotnet cli\n```\ndotnet add package Netjection --version 1.0.7\n```\nor package reference\n```\n\u003cPackageReference Include=\"Netjection\" Version=\"1.0.7\" /\u003e\n```\n\n## Usage\n\n```c#\n// Attribute without any parameter inject service as scoped\n// and implementation type will be interface name without \"I\" prefix.\n[Injectable]\npublic interface IUserService { }\n\npublic class UserService : IUserService { }\n```\n\n```c#\n// You can specify service lifetime.\n[Injectable(Lifetime.Singleton)]\npublic interface IProductService { }\n\npublic class ProductService : IProductService { }\n```\n\n```c#\n// You can specify implementation type.\n[Injectable(typeof(ConsoleLogger),Lifetime.Transient)]\npublic interface ICustomLogger { }\n\npublic class ConsoleLogger : ICustomLogger { }\n```\n\nOr scope specific attributes\n```c#\n// Attribute without any parameter inject service as scoped\n// and implementation type will be interface name without \"I\" prefix.\n[InjectAsSingleton]\npublic interface ISingletonService { }\n\npublic class SingletonService : ISingletonService { }\n\n// You can specify implementation type.\n[InjectAsScoped(typeof(ScopedServiceV2))]\npublic interface IScopedService { }\n\npublic class ScopedServiceV2 : IScopedService { }\n\n[InjectAsTransient]\npublic interface ITransientService { }\n\npublic class TransientService : ITransientService { }\n```\n\ncan be used with classes\n\n```c#\n[InjectAsSingleton]\npublic class DummyStorage\n{\n    public string GetDummyText() =\u003e \"Some Dummy Text\";\n}\n```\n\nNetjection can map configuration with classes and inject as singleton in DI container.\nit will use class name to search configuration section, but you can specify custom section name\nin attribute constructor.\n\n```json\n\"Options\": {\n    \"Url\": \"localhost\",\n    \"Port\": 8080,\n    \"UserName\": \"user\",\n    \"Password\": \"password\"\n  }\n```\n\n```c#\n[Configure] // or [Configure(\"CustomSectionName\")]\npublic class Options\n{\n    public string Url { get; set; }\n    public int Port { get; set; }\n    public string UserName { get; set; }\n    public string Password { get; set; }\n}\n```\nthen you can inject in constructor in three ways shown below.\n```c#\npublic class WhereOptionsAreInjected\n{\n    private readonly Test _test;\n    private readonly Test _testAsOptionsValue;\n    private readonly Test _testAsOptionsSnapshotValue;\n    public WhereOptionsAreInjected(Test test,IOptions\u003cTest\u003e testOptions,\n            IOptionsSnapshot\u003cTest\u003e testOptionsSnapshot)\n    {\n        _test = test;\n        _testAsOptionsValue = testOptions.Value;\n        _testAsOptionsSnapshotValue = testOptionsSnapshot.Value;\n    }\n}\n```\n\nand then use extension method on IServiceCollection to inject all service\n```c#\nusing Netjection\n\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.InjectServices(Assembly.GetExecutingAssembly(),Assembly.GetAssembly(typeof(SingletonService)));\n}\n```\n\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n\n## Icon\n[injection](https://thenounproject.com/icon/injection-5200198) by VectorsLab from \u003ca href=\"https://thenounproject.com/browse/icons/term/injection/\" target=\"_blank\" title=\"injection Icons\"\u003eNoun Project\u003c/a\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevazashvili%2Fnetjection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frevazashvili%2Fnetjection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frevazashvili%2Fnetjection/lists"}