{"id":19113897,"url":"https://github.com/ffernandolima/extensions-dependency-injection","last_synced_at":"2025-09-08T09:31:43.550Z","repository":{"id":116249351,"uuid":"274781444","full_name":"ffernandolima/extensions-dependency-injection","owner":"ffernandolima","description":"Exposes service factories. Exposes dependency injection modularization. Also, exposes some AOP (Aspect Oriented Programming) extensions which help registering and resolving proxies instead of concrete implementations through Microsoft built-in container with the main purpose of providing lazy loading/instantiation of resources.","archived":false,"fork":false,"pushed_at":"2023-11-07T17:37:35.000Z","size":1865,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-31T03:00:44.365Z","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/ffernandolima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2020-06-24T22:28:39.000Z","updated_at":"2024-10-11T03:42:25.000Z","dependencies_parsed_at":"2023-11-07T18:49:49.897Z","dependency_job_id":null,"html_url":"https://github.com/ffernandolima/extensions-dependency-injection","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ffernandolima/extensions-dependency-injection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffernandolima%2Fextensions-dependency-injection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffernandolima%2Fextensions-dependency-injection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffernandolima%2Fextensions-dependency-injection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffernandolima%2Fextensions-dependency-injection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ffernandolima","download_url":"https://codeload.github.com/ffernandolima/extensions-dependency-injection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ffernandolima%2Fextensions-dependency-injection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274165301,"owners_count":25233866,"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-08T02:00:09.813Z","response_time":121,"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":[],"created_at":"2024-11-09T04:39:30.588Z","updated_at":"2025-09-08T09:31:42.897Z","avatar_url":"https://github.com/ffernandolima.png","language":"C#","funding_links":["https://www.buymeacoffee.com/fernandolima"],"categories":[],"sub_categories":[],"readme":"# extensions-dependency-injection\n\nExposes service factories.\n\nExposes dependency injection modularization.\n\nAlso, exposes some AOP (Aspect Oriented Programming) extensions which help registering and resolving proxies instead of concrete implementations through Microsoft built-in container with the main purpose of providing lazy loading/instantiation of resources.\n\n[![build-and-tests Workflow Status](https://github.com/ffernandolima/extensions-dependency-injection/actions/workflows/build-and-tests.yml/badge.svg?branch=master)](https://github.com/ffernandolima/extensions-dependency-injection/actions/workflows/build-and-tests.yml?branch=master)\n\n[![build-and-publish Workflow Status](https://github.com/ffernandolima/extensions-dependency-injection/actions/workflows/build-and-publish.yml/badge.svg?branch=master)](https://github.com/ffernandolima/extensions-dependency-injection/actions/workflows/build-and-publish.yml?branch=master)\n\n | Package | NuGet |\n | ------- | ----- |\n | Extensions.DependencyInjection.Factories | [![Nuget](https://img.shields.io/badge/nuget-v2.3.0-blue) ![Nuget](https://img.shields.io/nuget/dt/Extensions.DependencyInjection.Factories)](https://www.nuget.org/packages/Extensions.DependencyInjection.Factories/2.3.0) |\n | Extensions.DependencyInjection.Modules | [![Nuget](https://img.shields.io/badge/nuget-v2.3.0-blue) ![Nuget](https://img.shields.io/nuget/dt/Extensions.DependencyInjection.Modules)](https://www.nuget.org/packages/Extensions.DependencyInjection.Modules/2.3.0) |\n | Extensions.DependencyInjection.Proxies | [![Nuget](https://img.shields.io/badge/nuget-v2.3.0-blue) ![Nuget](https://img.shields.io/nuget/dt/Extensions.DependencyInjection.Proxies)](https://www.nuget.org/packages/Extensions.DependencyInjection.Proxies/2.3.0) |\n\n## Installation\n\nIt is available on Nuget.\n\n```\nInstall-Package Extensions.DependencyInjection.Factories -Version 2.3.0\nInstall-Package Extensions.DependencyInjection.Modules -Version 2.3.0\nInstall-Package Extensions.DependencyInjection.Proxies -Version 2.3.0\n```\n\nP.S.: There's no dependency among the packages. Which one has its own features.\n\n## Usage\n\nThe following code demonstrates basic usage of service factory.\n\n```C#\n    public interface IAckService\n    { }\n\n    public interface IBazService\n    { }\n\n    public interface IQuxService\n    { }\n\n    public class AckService : IAckService\n    {\n        private readonly object _source;\n\n        public AckService(object source) =\u003e _source = source ?? throw new ArgumentNullException(nameof(source));\n    }\n\n    public class BazService : IBazService\n    {\n        public BazService()\n        { }\n    }\n\n    public class QuxService : IQuxService\n    {\n        private readonly ILogger\u003cQuxService\u003e _logger;\n        private readonly object _source;\n\n        public QuxService(ILogger\u003cQuxService\u003e logger, object source)\n        {\n            _logger = logger ?? throw new ArgumentNullException(nameof(logger));\n            _source = source ?? throw new ArgumentNullException(nameof(source));\n        }\n    }\n\n    public class Startup\n    {\n        public Startup(IConfiguration configuration)\n        {\n            Configuration = configuration;\n        }\n\n        public IConfiguration Configuration { get; }\n\n        public void ConfigureServices(IServiceCollection services)\n        {\n            if (services == null)\n            {\n                throw new ArgumentNullException(nameof(services));\n            }\n\n            Services.AddTransient\u003cIBazService, BazService\u003e();\n            Services.AddServiceFactory\u003cIBazService, BazService\u003e();\n\n            // Many ways of registering service factory:\n            // Services.AddServiceFactory\u003cIBazService, BazService\u003e(() =\u003e new BazService()); // Manual instantiation\n            // Services.AddServiceFactory\u003cIBazService, BazService\u003e((object[] args) =\u003e new BazService()); // Receives args\n            // Services.AddServiceFactory\u003cIBazService, BazService\u003e((IServiceProvider provider, object[] args) =\u003e new BazService()); // Receives ServiceProvider and args\n            // Services.AddServiceFactory\u003cIBazService, BazService\u003e((IServiceProvider provider, object[] args) =\u003e provider.GetServiceOrCreateInstance\u003cIBazService\u003e()); // Requires IBazService registration\n            // Services.AddServiceFactory\u003cIBazService, BazService\u003e((IServiceProvider provider, object[] args) =\u003e provider.GetServiceOrCreateInstance\u003cBazService\u003e()); // No matter IBazService was registered or not into DI container\n\n            Services.AddServiceFactory\u003cIAckService, AckService\u003e((IServiceProvider provider, object[] args) =\u003e provider.CreateInstance\u003cAckService\u003e(args)); // IAckService must not be registered into DI container\n            Services.AddServiceFactory\u003cIQuxService, QuxService\u003e((IServiceProvider provider, object[] args) =\u003e provider.CreateInstance\u003cQuxService\u003e(args)); // IQuxService must not be registered into DI container\n        }\n    }\n\n    public class DIController : Controller\n    {\n        private readonly IServiceFactory\u003cIBazService\u003e _bazServiceFactory;\n        private readonly IServiceFactory\u003cIAckService\u003e _ackServiceFactory;\n        private readonly IServiceFactory\u003cIQuxService\u003e _quxServiceFactory;\n\n        public DIController(IServiceFactory\u003cIBazService\u003e bazServiceFactory, IServiceFactory\u003cIAckService\u003e ackServiceFactory, IServiceFactory\u003cIQuxService\u003e quxServiceFactory)\n        {\n            _bazServiceFactory = bazServiceFactory ?? throw new ArgumentNullException(nameof(bazServiceFactory));\n            _ackServiceFactory = ackServiceFactory ?? throw new ArgumentNullException(nameof(ackServiceFactory));\n            _quxServiceFactory = quxServiceFactory ?? throw new ArgumentNullException(nameof(quxServiceFactory));\n        }\n\n        public IActionResult Get()\n        {\n            var bazService = _bazServiceFactory.GetService();\n            var ackService = _bazServiceFactory.GetService(new object());\n            var quxService = _bazServiceFactory.GetService(new object());\n\n            return Ok();\n        }\n    }\n```\n\nThe following code demonstrates basic usage of modules.\n\n```C#\n\n    public class ServicesModule : IModuleRegistry\n    {\n        public string ModuleName =\u003e nameof(ServicesModule);\n\n        public void Registry(IServiceCollection services, IConfiguration configuration = null, ILoggerFactory loggerFactory = null, IHostEnvironment hostEnvironment = null)\n        {\n            if (services == null)\n            {\n                throw new ArgumentNullException(nameof(services));\n            }\n\n            // Register your services here.\n        }\n    }\n\n    public class MessagingModule : IModuleRegistry\n    {\n        public string ModuleName =\u003e nameof(MessagingModule);\n\n        public void Registry(IServiceCollection services, IConfiguration configuration = null, ILoggerFactory loggerFactory = null, IHostEnvironment hostEnvironment = null)\n        {\n            if (services == null)\n            {\n                throw new ArgumentNullException(nameof(services));\n            }\n\n            // Register your messaging services here.\n        }\n    }\n\n    public class Startup\n    {\n        public Startup(IConfiguration configuration)\n        {\n            Configuration = configuration;\n        }\n\n        public IConfiguration Configuration { get; }\n\n        public void ConfigureServices(IServiceCollection services)\n        {\n            if (services == null)\n            {\n                throw new ArgumentNullException(nameof(services));\n            }\n\n            IModuleCollection moduleCollection = new ModuleCollection();\n            moduleCollection.AddModule\u003cServicesModule\u003e()\n                            .AddModule\u003cMessagingModule\u003e()\n                            .Registry(services, Configuration); // Configuration, LoggerFactory and HostEnvironment are optional parameters.\n        }\n    }\n\n```\n\nThe following code demonstrates basic usage of proxies.\n\n```C#\n\n    public interface IBarService\n    {\n        string Execute();\n    }\n\n    public interface IFooService\n    {\n        string Execute();\n    }\n\n    public class FooService : IFooService\n    {\n        private readonly IBarService _barService;\n\n        // At this moment barService is just a proxy, it wasn't instantiated yet\n        public FooService(IBarService barService) =\u003e _barService = barService ?? throw new ArgumentNullException(nameof(barService));\n\n        // When invoked, it gets instantiated\n        public string Execute() =\u003e $\"Foo-{_barService.Execute()}\";\n    }\n\n    public class BarService : IBarService\n    {\n        public string Execute() =\u003e $\"Bar\";\n    }\n\n    public class Startup\n    {\n        public Startup(IConfiguration configuration)\n        {\n            Configuration = configuration;\n        }\n\n        public IConfiguration Configuration { get; }\n\n        public void ConfigureServices(IServiceCollection services)\n        {\n            if (services == null)\n            {\n                throw new ArgumentNullException(nameof(services));\n            }\n\n            // Many ways of registering services as proxies:\n            services.AddTransientProxy\u003cIFooService, FooService\u003e();\n            services.AddTransientProxy\u003cIBarService, BarService\u003e();\n\n            // You can also provide an ImplementationFactory that will be used to create the service.\n            // services.AddTransientProxy\u003cIFooService, FooService\u003e(() =\u003e new FooService(new BarService()));\n            // services.AddTransientProxy\u003cIBarService, BarService\u003e(() =\u003e new BarService());\n\n            // Or:\n            // services.AddTransient\u003cIFooService\u003e(provider =\u003e provider.CreateProxy\u003cIFooService, FooService\u003e());\n            // services.AddTransient\u003cIBarService\u003e(provider =\u003e provider.CreateProxy\u003cIBarService, BarService\u003e());\n\n            // You can also provide an ImplementationFactory that will be used to create the service.\n            // services.AddTransient\u003cIFooService\u003e(provider =\u003e provider.CreateProxy\u003cIFooService, FooService\u003e(() =\u003e new FooService(provider.GetService\u003cIBarService\u003e())));\n            // services.AddTransient\u003cIBarService\u003e(provider =\u003e provider.CreateProxy\u003cIBarService, BarService\u003e(() =\u003e new BarService()));\n\n            // All Lifetimes are available (Transient, Scoped and Singleton).\n        }\n    }\n\n    public class FooController : Controller\n    {\n        private readonly IFooService _fooService;\n\n        // At this moment fooService is just a proxy, it wasn't instantiated yet \n        // Also its dependency barService is just a proxy, it wasn't instantiated too\n        public FooController(IFooService fooService) =\u003e _fooService = fooService ?? throw new ArgumentNullException(nameof(fooService));\n\n        public IActionResult Get()\n        {\n            // When invoked, it gets instantiated\n            // barService is still a proxy\n            var result = fooService.Execute();\n\n            return Ok(result);\n        }\n    }\n\n```\n\n## Support / Contributing\nIf you want to help with the project, feel free to open pull requests and submit issues. \n\n## Donate\n\nIf you would like to show your support for this project, then please feel free to buy me a coffee.\n\n\u003ca href=\"https://www.buymeacoffee.com/fernandolima\" target=\"_blank\"\u003e\u003cimg src=\"https://www.buymeacoffee.com/assets/img/custom_images/white_img.png\" alt=\"Buy Me A Coffee\" style=\"height: auto !important;width: auto !important;\" \u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fffernandolima%2Fextensions-dependency-injection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fffernandolima%2Fextensions-dependency-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fffernandolima%2Fextensions-dependency-injection/lists"}