{"id":13629414,"url":"https://github.com/ignatandrei/functionsdi","last_synced_at":"2025-06-12T01:09:57.635Z","repository":{"id":37008676,"uuid":"504388211","full_name":"ignatandrei/FunctionsDI","owner":"ignatandrei","description":"DI for functions","archived":false,"fork":false,"pushed_at":"2024-01-06T22:29:09.000Z","size":74,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-06T12:44:37.311Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ignatandrei.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},"funding":{"github":["ignatandrei"]}},"created_at":"2022-06-17T04:03:53.000Z","updated_at":"2023-09-03T17:52:05.000Z","dependencies_parsed_at":"2024-08-01T22:51:58.622Z","dependency_job_id":null,"html_url":"https://github.com/ignatandrei/FunctionsDI","commit_stats":{"total_commits":34,"total_committers":2,"mean_commits":17.0,"dds":0.02941176470588236,"last_synced_commit":"2440bfad2e11ed3d09ab374d724333b9656de1c4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ignatandrei/FunctionsDI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FFunctionsDI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FFunctionsDI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FFunctionsDI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FFunctionsDI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ignatandrei","download_url":"https://codeload.github.com/ignatandrei/FunctionsDI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignatandrei%2FFunctionsDI/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259374947,"owners_count":22847873,"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":[],"created_at":"2024-08-01T22:01:09.914Z","updated_at":"2025-06-12T01:09:57.610Z","avatar_url":"https://github.com/ignatandrei.png","language":"C#","funding_links":["https://github.com/sponsors/ignatandrei"],"categories":["Content"],"sub_categories":["22. [RSCG_FunctionsWithDI](https://ignatandrei.github.io/RSCG_Examples/v2/docs/RSCG_FunctionsWithDI) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category"],"readme":"# FunctionsDI\n\n[![Nuget](https://img.shields.io/nuget/v/RSCG_FunctionsWithDI)](https://www.nuget.org/packages/RSCG_FunctionsWithDI)\n\nGenerate (constructor) and functions calls similar with ASP.NET Core WebAPI ( [FromServices] will be provided by DI )\nAlso, verifies for null  .\n\n# Usage 1 - generate constructors from methods\n\nReference into the csproj\n\n```xml\n\u003cItemGroup\u003e\n    \u003cPackageReference Include=\"RSCG_FunctionsWithDI\" Version=\"2022.7.7.636\" ReferenceOutputAssembly=\"false\" OutputItemType=\"Analyzer\" /\u003e\n    \u003cPackageReference Include=\"RSCG_FunctionsWithDI_Base\" Version=\"2022.7.7.636\" /\u003e\n\u003c/ItemGroup\u003e \t\n\u003cPropertyGroup\u003e\n\t\t\u003cEmitCompilerGeneratedFiles\u003etrue\u003c/EmitCompilerGeneratedFiles\u003e\n\t\t\u003cCompilerGeneratedFilesOutputPath\u003e$(BaseIntermediateOutputPath)GeneratedX\u003c/CompilerGeneratedFilesOutputPath\u003e\n\t\u003c/PropertyGroup\u003e\n\n```\n\nThen for every class you can write [FromServices]\n\n```csharp\nusing RSCG_FunctionsWithDI_Base;\n//namespace if necessary\npublic partial class TestDIFunction\n{\n    public bool TestMyFunc1([FromServices] TestDI1 t1, [FromServices] TestDI2 t2, int x, int y)\n    {\n        return true;\n    }\n    //more functions\n}\n```\n\ngenerates the constructor with needed details \n\n```csharp\n\npublic partial class TestDIFunction\n{ \nprivate TestDI1 _TestDI1;\nprivate TestDI2 _TestDI2;\npublic TestDIFunction  (TestDI1 _TestDI1,TestDI2 _TestDI2) //constructor generated with needed DI\n { \nthis._TestDI1=_TestDI1;\nthis._TestDI2=_TestDI2;\n\n } //end constructor \n\n//making call to TestMyFunc1\npublic bool TestMyFunc1(int  x,int  y){ \nvar t1 = this._TestDI1  ;\nif(t1 == null) throw new ArgumentException(\" service TestDI1  is null in TestDIFunction \");\nvar t2 = this._TestDI2  ;\nif(t2 == null) throw new ArgumentException(\" service TestDI2  is null in TestDIFunction \");\nreturn  TestMyFunc1(t1,t2,x,y);\n}\n\n```\n\nso you can call \n```csharp\n\nvar test=serviceProvider.GetService\u003cTestDIFunction\u003e();\nConsole.WriteLine(test.TestMyFunc1(10,3)); // calling without the [FromServices] arguments\n\n```\n\n# Usage 2 - generate constructors from fields / constructors\n```xml\n\u003cItemGroup\u003e\n    \u003cPackageReference Include=\"RSCG_FunctionsWithDI\" Version=\"2022.7.7.636\" ReferenceOutputAssembly=\"false\" OutputItemType=\"Analyzer\" /\u003e\n    \u003cPackageReference Include=\"RSCG_FunctionsWithDI_Base\" Version=\"2022.7.7.636\" /\u003e\n\u003c/ItemGroup\u003e\t\n\u003cPropertyGroup\u003e\n\t\t\u003cEmitCompilerGeneratedFiles\u003etrue\u003c/EmitCompilerGeneratedFiles\u003e\n\t\t\u003cCompilerGeneratedFilesOutputPath\u003e$(BaseIntermediateOutputPath)GeneratedX\u003c/CompilerGeneratedFilesOutputPath\u003e\n\t\u003c/PropertyGroup\u003e\n\n```\nAssuming this classes, that you want to keep a minimum of parameters constructors \n```csharp\npublic partial class TestDIFunctionAdvWithConstructor\n    {\n        [RSCG_FunctionsWithDI_Base.FromServices]\n        private TestDI1 NewTestDI1;\n\n        [RSCG_FunctionsWithDI_Base.FromServices]\n        public TestDI2 NewTestDI2 { get; set; }\n\n        public readonly TestDI3 myTestDI3;\n\n        private TestDIFunctionAdvWithConstructor(TestDI3 test)\n        {\n            myTestDI3= test;\n        }\n        \n    }\n    public partial class TestDIFunctionAdvNoConstructor\n    {\n        [RSCG_FunctionsWithDI_Base.FromServices]\n        public TestDI1 NewTestDI1;\n\n        [RSCG_FunctionsWithDI_Base.FromServices]\n        private TestDI2 NewTestDI2 { get; set; }\n\n\n\n\n    }\n```\nthe generator will generate \n\n```csharp\nnamespace TestFunctionsWithDI\n\n{ \npublic partial class TestDIFunctionAdvNoConstructor\n{ \npublic TestDIFunctionAdvNoConstructor( TestDI1 _NewTestDI1,TestDI2 _NewTestDI2 ) \n{ \nthis.NewTestDI1 = _NewTestDI1; \nthis.NewTestDI2 = _NewTestDI2; \n}//end constructor \n\n }//class\n }//namespace\n\n\nnamespace TestFunctionsWithDI\n\n{ \npublic partial class TestDIFunctionAdvWithConstructor\n{ \npublic TestDIFunctionAdvWithConstructor(TestDI3 test, TestDI1 _NewTestDI1, TestDI2 _NewTestDI2) : this (test) \n{ \nthis.NewTestDI1 = _NewTestDI1; \nthis.NewTestDI2 = _NewTestDI2; \n}//end constructor \n\n }//class\n }//namespace\n```\n\nEnjoy!\n\n# More Roslyn Source Code Generators\n\nYou can find more RSCG with examples at [Roslyn Source Code Generators](https://ignatandrei.github.io/RSCG_Examples/v2/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignatandrei%2Ffunctionsdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fignatandrei%2Ffunctionsdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignatandrei%2Ffunctionsdi/lists"}