{"id":13430750,"url":"https://github.com/davidrevoledo/Inyector","last_synced_at":"2025-03-16T06:31:10.384Z","repository":{"id":97733332,"uuid":"112041599","full_name":"davidrevoledo/Inyector","owner":"davidrevoledo","description":"Library to Implement Automatic dependency injection by Configuration over Scaned Assemblies","archived":false,"fork":false,"pushed_at":"2019-10-31T11:29:21.000Z","size":103,"stargazers_count":13,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-26T22:33:01.978Z","etag":null,"topics":["asp-net-core","aspnetcore","csharp","dependency-injection"],"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/davidrevoledo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING.txt","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":"2017-11-25T23:26:10.000Z","updated_at":"2020-09-20T20:03:10.000Z","dependencies_parsed_at":"2023-03-13T16:09:34.379Z","dependency_job_id":null,"html_url":"https://github.com/davidrevoledo/Inyector","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/davidrevoledo%2FInyector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidrevoledo%2FInyector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidrevoledo%2FInyector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidrevoledo%2FInyector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidrevoledo","download_url":"https://codeload.github.com/davidrevoledo/Inyector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221656367,"owners_count":16858754,"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":["asp-net-core","aspnetcore","csharp","dependency-injection"],"created_at":"2024-07-31T02:00:57.384Z","updated_at":"2024-10-27T09:30:45.521Z","avatar_url":"https://github.com/davidrevoledo.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具"],"sub_categories":["IOC","控制反转IOC"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"inyector.jpg\" alt=\"Inyector\" width=\"100\"/\u003e\n\u003c/p\u003e\n\n# Inyector\n\nWhat inyector is ? \n\nInjector is a very simple tool that allow application that use Microsoft DI inyection to auto configure things.\n\n***This Library Is NOT*** a dependency injection engine.\n\nIt is simply an abstraction layer to configure our objects no matter what technology we use as an injection engine.\n\nYou can use Injector with your favorites libraries like Asp.Net Core DI, Autofac, Ninject and others ...\n\n[![CodeFactor](https://www.codefactor.io/repository/github/davidrevoledo/inyector/badge)](https://www.codefactor.io/repository/github/davidrevoledo/inyector)\n[![Build status](https://ci.appveyor.com/api/projects/status/j7f6vfv3s4nwwak6?svg=true)](https://ci.appveyor.com/project/davidrevoledo/inyector)\n![NuGet](https://img.shields.io/nuget/dt/Inyector.svg)\n![NuGet](https://img.shields.io/nuget/v/Inyector.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\n### Installation\nGrab the latest Inyector NuGet package and install in your solution. https://www.nuget.org/packages/Inyector/\n```sh\nPM \u003e Install-Package Inyector \nNET CLI - dotnet add package Inyector \npaket add Inyector --version 1.2\n```\n\n### How to use\n           -  Scan (Allow you to declare what assemblies Inyector need to listen to apply the rules, this is made to avoid processing all the referenced assmeblies)\n```c#\n           c.Scan(typeof(Startup).Assembly)\n```    \n           \n           - Modes \n           (The way to declare inyection engine without repeat code,\n           you define a Mode with name an with an action that get both types)\n           \n```c#\n           c.AddMode(\"MyCustomMode\", (type, interf) =\u003e services.AddScoped(interf, type));\n```    \n           \n           - Rules\n            You can apply any rule in an assembly or in all the shared scaned assemblies\n            You can create your custom rules as well.\n           \n           - AddRuleForNamingConvention\n           (You can auto-inyect all the objects that have the convention of Class and IClass (Interface) )\n            \n          -  AddRuleForEndsWithNamingConvention\n           (You can auto-inyect all the objects that finish with a list of key values like \"Helper\" and \"Factory\" then\n           if you have FooFactory and IFoo2Factory they can be auto-inyected)\n           \n           - AvoidInyectorAttribute you can avoid to apply any Inyector Rule\n           with this attribute\n           \n           - InyectAttribute \n           with this attribute you can declare what object Inyector should auto-inyect\n           You set the Interface and the Mode, if not Default will the mode (if exist) that apply to this Attribute\n           \n```c#\n               [Inyect(typeof(IFooHelper))]\n               public class CarHelper : IFooHelper\n               {\n               }\n```    \n   \n```c#\n               [Inyect]\n               public class CarHelper \n               {\n               }\n```    \n   \n```c#\n               [Inyect(typeof(IFooHelper), mode : \"MyCustomMode\")]\n               public class CarHelper : IFooHelper\n               {\n               }\n```    \n\n#### AspNetCore\n```sh\nPM \u003e Install-Package Inyector-AspNetCore \t\nNET CLI - dotnet add package Inyector-AspNetCore \n```\n\nWith AspNet core you can avoid to configure modes, using the ServiceLifetime Enum to apply pre-builded Modes,\nAlso you can define your owns.\n\n```c#\n        // This method gets called by the runtime. Use this method to add services to the container.\n        public void ConfigureServices(IServiceCollection services)\n        {\n            services.AddMvc();\n\n            // use injector\n            services.UseInjector(configurations =\u003e\n            {\n                configurations.Scan(typeof(Startup).Assembly)\n                    .DefaultMode(services, ServiceLifetime.Singleton)\n                    .AddRuleForNamingConvention(ServiceLifetime.Singleton);\n            });\n        }\n```\n\n#### Raw\nTo use injector directly you have call ```C# InyectorStartup ``` class like this :\n```c#\nInyectorStartup.Init(c =\u003e\n            {\n                c.Scan(typeof(AnyClass).Assembly)\n                    .AddRuleForNamingConvention((type, interf) =\u003e services.AddSingleton(interf, type))\n                    .AddRule((type, inter)=\u003e services.RegisterType(inter, type));\n            });\n```\n\n\n\n### Licensing\nInyector is licensed under the MIT License\n\n### Development\nWant to contribute? Great!\n\nMade with ❤ in [DGENIX](https://www.dgenix.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidrevoledo%2FInyector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidrevoledo%2FInyector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidrevoledo%2FInyector/lists"}