{"id":30673767,"url":"https://github.com/starcruisestudios/phxinject","last_synced_at":"2025-09-01T06:04:32.326Z","repository":{"id":144661095,"uuid":"516620379","full_name":"StarCruiseStudios/PhxInject","owner":"StarCruiseStudios","description":"Compile time dependency injection for .NET.","archived":false,"fork":false,"pushed_at":"2025-07-17T07:54:14.000Z","size":1718,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-15T07:33:50.247Z","etag":null,"topics":["csharp","dependency-injection","roslyn","roslyn-generator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StarCruiseStudios.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-07-22T05:22:14.000Z","updated_at":"2025-07-17T07:54:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"42f87f42-fc6b-45e9-a6a3-04db77f70518","html_url":"https://github.com/StarCruiseStudios/PhxInject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StarCruiseStudios/PhxInject","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxInject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxInject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxInject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxInject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StarCruiseStudios","download_url":"https://codeload.github.com/StarCruiseStudios/PhxInject/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StarCruiseStudios%2FPhxInject/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273081103,"owners_count":25042275,"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-09-01T02:00:09.058Z","response_time":120,"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":["csharp","dependency-injection","roslyn","roslyn-generator"],"created_at":"2025-09-01T06:04:31.108Z","updated_at":"2025-09-01T06:04:32.292Z","avatar_url":"https://github.com/StarCruiseStudios.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phx.Inject\n\nCompile time dependency injection for .NET.\n\nWritten as a Roslyn Source Generator, PHX.Inject will analyze dependency\nspecifications defined in your code and generate the source code that performs\nthe injection and linking at build time. This results in blazing fast injection\nat runtime, and quick identification of dependency issues at compile time.\n\n## Set up\n\nPHX.Inject can be installed as a Nuget package using the .NET CLI.\n\n```shell\ndotnet add package Phx.Inject.Generator\n```\n\n## Getting Started\n\nThe simplest set up consists of a `Specification` and an `Injector`.\n\n```csharp\nusing Phx.Inject;\n\n[Specification]\ninternal static class TestSpecification {\n    [Factory]\n    internal static int GetIntValue() {\n        return 10;\n    }\n}\n\n[Injector(\n    typeof(TestSpecification)\n)]\npublic interface ITestInjector {\n    public int GetInt();\n}\n```\n\nThe dependencies can be retrieved in code by instantiating the generated\ninjector.\n\n```csharp\nITestInjector injector = new GeneratedTestInjector();\nint myInt = injector.GetInt();\n\nVerify.That(myInt.IsEqualTo(10));\n```\n\nSpecifications contain Factories and Builders that define how dependencies\nshould be linked and constructed. The Injector is the interface used to\nconstruct and access those dependencies.\n\nThe example above will generate a new class `GeneratedTestInjector` that\nimplements the `ITestInjector` interface. The `GetInt()` method will be linked\nto the `TestSpecification.GetIntValue()` method based on the return type of the\nmethods.\n\n## Something More Complicated\n\nThe power of a Dependency Injection Framework comes from it's ability to define\na graph of dependencies, one node at a time, and automatically resolve the links\nbetween each of those nodes.\n\n```csharp\nusing Phx.Inject;\n\n[Specification]\ninternal static class TestSpecification {\n    [Factory]\n    internal static MyClass GetMyClass(int intValue) {\n        return new MyClass(intValue);\n    }\n    \n    [Builder]\n    internal static void GetMyBuiltClass(MyBuiltClass target, int intValue) {\n        target.Value = intValue;\n    }\n     \n    [Factory]\n    internal static int GetIntValue() {\n        return 10;\n    }\n}\n\n[Injector(\n    typeof(TestSpecification)\n)]\npublic interface ITestInjector {\n    public MyClass GetMyClass();\n    public void Build(MyBuiltClass target);\n}\n```\n\nIn this example, the `GetMyClass` factory in the specification accepts an\nargument. This argument will be invoked with the linked int value dependency in\nthe generated injector.\n\nThis example also contains a builder. A builder is similar to a factory, except\nthe instance is not constructed by the method, it is passed in and the method\nwill set up properties on the object. This pattern is useful when you do not\nhave control of the instantiation of the instance, but still want it configured\nwith values from the dependency graph.\n\n```csharp\nITestInjector injector = new GeneratedTestInjector();\nMyClass myClass = injector.GetMyClass();\nMyBuiltClass myBuiltClass = new MyBuiltClass();\ninjector.Build(myBuiltClass);\n\nVerify.That(myClass.Value.IsEqualTo(10));\nVerify.That(myBuiltClass.Value.IsEqualTo(10));\n```\n\nSee the [Documentation](Documentation/Index.md) for more details.\n\n---\n\n\u003cdiv align=\"center\"\u003e\nCopyright (c) 2022 Star Cruise Studios LLC. All rights reserved.\u003cbr/\u003e\nLicensed under the Apache License, Version 2.0.\u003cbr/\u003e\nSee http://www.apache.org/licenses/LICENSE-2.0 for full license information.\u003cbr/\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarcruisestudios%2Fphxinject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarcruisestudios%2Fphxinject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarcruisestudios%2Fphxinject/lists"}