{"id":13629678,"url":"https://github.com/giggio/sourceinject","last_synced_at":"2025-03-16T19:31:54.038Z","repository":{"id":66068094,"uuid":"350144767","full_name":"giggio/sourceinject","owner":"giggio","description":"A source generator for C# that uses Roslyn (the C# compiler) to allow you to generate your dependencies injection during compile time. ","archived":false,"fork":false,"pushed_at":"2022-10-15T18:15:54.000Z","size":722,"stargazers_count":80,"open_issues_count":2,"forks_count":4,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-05-23T07:52:22.199Z","etag":null,"topics":[],"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/giggio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2021-03-21T23:18:08.000Z","updated_at":"2024-05-17T08:05:06.000Z","dependencies_parsed_at":"2023-03-13T20:30:57.485Z","dependency_job_id":null,"html_url":"https://github.com/giggio/sourceinject","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggio%2Fsourceinject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggio%2Fsourceinject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggio%2Fsourceinject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giggio%2Fsourceinject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giggio","download_url":"https://codeload.github.com/giggio/sourceinject/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826791,"owners_count":20354220,"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:16.360Z","updated_at":"2025-03-16T19:31:53.709Z","avatar_url":"https://github.com/giggio.png","language":"C#","funding_links":[],"categories":["Do not want to test 113 ( old ISourceGenerator )","Bibliotecas úteis"],"sub_categories":["1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category",".NET"],"readme":"# Source Inject\n\nA source generator for C# that uses [Roslyn](https://github.com/dotnet/roslyn) (the C# compiler) to allow you to generate\nyour dependencies injection during compile time. By doing this\nyou avoid using reflection and services are automatically\nregistered.\n\n[![NuGet version (sourceinject)](https://img.shields.io/nuget/v/sourceinject?color=blue)](https://www.nuget.org/packages/sourceinject/)\n[![Build](https://github.com/giggio/sourceinject/actions/workflows/dotnet.yml/badge.svg)](https://github.com/giggio/sourceinject/actions/workflows/dotnet.yml)\n[![License](https://img.shields.io/github/license/giggio/sourceinject.svg)](https://github.com/giggio/sourceinject/blob/master/LICENSE.txt)\n\n## How to use it\n\nInstall it and add an attribute to the classes you want injected in your service provider, like so:\n\n```csharp\n[Inject]\npublic class ExampleService\n{\n    private readonly AnotherService anotherService;\n\n    public ExampleService(AnotherService anotherService) =\u003e\n        this.anotherService = anotherService;\n\n    public string GetValue() =\u003e anotherService.Value;\n}\n\n[Inject(ServiceLifetime.Singleton)]\npublic class AnotherService\n{\n    public string Value =\u003e \"Hello World!\";\n}\n```\n\nAs you can see above you can define the lifetime. The default lifetime is transient.\nYou can also use the following attributes:\n\n- `InjectSingletonAttribute`\n- `InjectScopedAttribute`\n- `InjectTransientAttribute`\n\nThe last one is the same as using `Inject` without any arguments.\n\nYou then have to call the `Discover` method so these classes are found and the source is generated.\nYou can then require them using constructor injection or service locator, for example:\n\n```csharp\nvar services = new ServiceCollection();\nservices.Discover();\nvar serviceProvider = services.BuildServiceProvider();\nvar exampleService = serviceProvider.GetRequiredService\u003cExampleService\u003e();\n```\n\nYou can also discover services in other assemblies. To be able to do this you have to call\nthe method `DiscoverIn\u003cAssemblyName\u003e` or `\u003cAssemblyName\u003eDiscoverer.Discover(services)`. If your\nassembly name has dots `.` in them they will be replaced by underscore `_`.\n\nAll these methods (`Discover` et all) and attributes will be generated in your project for you.\n\nYou can see the generated code using Visual Studio. See [here](https://docs.microsoft.com/en-us/visualstudio/releases/2019/media/16.9/16.9_p3_source_generators_node.png) for an example.\n\n## Installing\n\nThe package is available ([on NuGet](https://www.nuget.org/packages/sourceinject).\nTo install from the command line:\n\n```shell\ndotnet add package sourceinject\n```\n\nOr use the Package Manager in Visual Studio.\n\n## Contributing\n\nThe main supported IDE for development is Visual Studio 2019.\n\nQuestions, comments, bug reports, and pull requests are all welcome.\nBug reports that include steps to reproduce (including code) are\npreferred. Even better, make them in the form of pull requests.\nBefore you start to work on an existing issue, check if it is not assigned\nto anyone yet, and if it is, talk to that person.\n\n## Maintainers/Core team\n\n- [Giovanni Bassi](http://blog.lambda3.com.br/L3/giovannibassi/), aka Giggio,\n    [Lambda3](http://www.lambda3.com.br), [@giovannibassi](https://twitter.com/giovannibassi)\n\nContributors can be found at the [contributors](https://github.com/giggio/sourceinject/graphs/contributors) page on Github.\n\n## License\n\nThis software is open source, licensed under the MIT License.\nSee [LICENSE](https://github.com/giggio/sourceinject/blob/master/LICENSE) for details.\nCheck out the terms of the license before you contribute, fork, copy or do anything\nwith the code. If you decide to contribute you agree to grant copyright of all your contribution to this project and agree to\nmention clearly if do not agree to these terms. Your work will be licensed with the project at MIT, along the rest of the code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiggio%2Fsourceinject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiggio%2Fsourceinject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiggio%2Fsourceinject/lists"}