{"id":13458914,"url":"https://github.com/Neoteroi/rodi","last_synced_at":"2025-03-24T16:31:09.242Z","repository":{"id":42725352,"uuid":"151482318","full_name":"Neoteroi/rodi","owner":"Neoteroi","description":"Implementation of dependency injection for Python 3","archived":false,"fork":false,"pushed_at":"2024-09-03T21:03:16.000Z","size":185,"stargazers_count":180,"open_issues_count":14,"forks_count":18,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-11-24T20:46:25.538Z","etag":null,"topics":["dependency-injection","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/Neoteroi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-03T21:23:57.000Z","updated_at":"2024-11-14T07:30:02.000Z","dependencies_parsed_at":"2023-11-11T17:25:59.793Z","dependency_job_id":"f5e55dc2-ee36-46f8-bed0-2a51c712ec8d","html_url":"https://github.com/Neoteroi/rodi","commit_stats":{"total_commits":58,"total_committers":6,"mean_commits":9.666666666666666,"dds":0.08620689655172409,"last_synced_commit":"ee5545317ea58622927f4bbe943b095daca2f42e"},"previous_names":["robertoprevato/rodi"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neoteroi%2Frodi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neoteroi%2Frodi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neoteroi%2Frodi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neoteroi%2Frodi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neoteroi","download_url":"https://codeload.github.com/Neoteroi/rodi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245308494,"owners_count":20594260,"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":["dependency-injection","python"],"created_at":"2024-07-31T09:00:59.679Z","updated_at":"2025-03-24T16:31:08.982Z","avatar_url":"https://github.com/Neoteroi.png","language":"Python","readme":"![Build](https://github.com/Neoteroi/rodi/workflows/Build/badge.svg)\n[![pypi](https://img.shields.io/pypi/v/rodi.svg)](https://pypi.python.org/pypi/rodi)\n[![versions](https://img.shields.io/pypi/pyversions/rodi.svg)](https://github.com/Neoteroi/rodi)\n[![codecov](https://codecov.io/gh/Neoteroi/rodi/branch/main/graph/badge.svg?token=VzAnusWIZt)](https://codecov.io/gh/Neoteroi/rodi)\n[![license](https://img.shields.io/github/license/Neoteroi/rodi.svg)](https://github.com/Neoteroi/rodi/blob/main/LICENSE)\n\n# Implementation of dependency injection for Python 3\n\n**Features:**\n\n* types resolution by signature types annotations (_type hints_)\n* types resolution by class annotations (_type hints_)\n* types resolution by names and aliases (_convention over configuration_)\n* unintrusive: builds objects graph **without** the need to change the\n  source code of classes\n* minimum overhead to obtain services, once the objects graph is built\n* support for singletons, transient, and scoped services\n\nThis library is freely inspired by .NET Standard\n`Microsoft.Extensions.DependencyInjection` implementation (_ref. [MSDN,\nDependency injection in ASP.NET\nCore](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1),\n[Using dependency injection in a .Net Core console\napplication](https://andrewlock.net/using-dependency-injection-in-a-net-core-console-application/)_).\nThe `ContainerProtocol` for v2 is inspired by [punq](https://github.com/bobthemighty/punq).\n\n## Installation\n\n```bash\npip install rodi\n```\n\n## Efficient\n\n`rodi` works by inspecting code **once** at runtime, to generate\nfunctions that return instances of desired types - as long as the object graph\nis not altered. Inspections are done either on constructors\n(__\u0026#95;\u0026#95;init\u0026#95;\u0026#95;__) or class annotations. Validation steps, for\nexample to detect circular dependencies or missing services, are done when\nbuilding these functions, so additional validation is not needed when\nactivating services.\n\n## Flexible\n\n`rodi` offers two code APIs:\n\n- one is kept as generic as possible, using a `ContainerProtocol` for scenarios\n  in which it is desirable being able to replace `rodi` with alternative\n  implementations of dependency injection for Python. The protocol only expects\n  a class being able to `register` and `resolve` types, and to tell if a type\n  is configured in it (`__contains__`). Even if other implementations of DI\n  don´t implement these three methods, it should be easy to use\n  [composition](https://en.wikipedia.org/wiki/Composition_over_inheritance) to\n  wrap other libraries with a compatible class.\n- one is a more concrete implementation, for scenarios where it's not desirable\n  to consider alternative implementations of dependency injection.\n\nFor this reason, the examples report two ways to achieve certain things.\n\n### Examples\n\nFor examples, refer to the [examples folder](./examples).\n\n### Recommended practices\n\nAll services should be configured once, when an application starts, and the\nobject graph should *not* be altered during normal program execution.\nExample: if you build a web application, configure the object graph when\nbootstrapping the application, avoid altering the `Container` configuration\nwhile handling web requests.\n\nAim at keeping the `Container` and service graphs abstracted from the front-end\nlayer of your application, and avoid mixing runtime values with container\nconfiguration. Example: if you build a web application, avoid if possible\nrelying on the HTTP Request object being a service registered in your container.\n\n## Service life style:\n\n* singleton - instantiated only once per service provider\n* transient - services are instantiated every time they are required\n* scoped - instantiated only once per root service resolution call\n  (e.g. once per web request)\n\n## Usage in BlackSheep\n\n`rodi` is used in the [BlackSheep](https://www.neoteroi.dev/blacksheep/)\nweb framework to implement [dependency injection](https://www.neoteroi.dev/blacksheep/dependency-injection/) for\nrequest handlers.\n\n# Documentation\n\nUnder construction. 🚧\n","funding_links":[],"categories":["Software","Python","Topics Index"],"sub_categories":["DI components of Web frameworks","Commonly Useful Knowledge"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNeoteroi%2Frodi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNeoteroi%2Frodi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNeoteroi%2Frodi/lists"}