ivankorobkov / python-inject

Python dependency injection
Apache License 2.0
672 stars 77 forks source link

Feature request: support dynamic binding configuration #19

Closed gshklover closed 6 years ago

gshklover commented 6 years ago

It seems that currently, one needs to provide configuration once at initialization. In some scenarios the complete set of bound classes might not be available at injector initialization (example: if injector is required while dynamically initializing other modules that require injector).

Please add a method to extend injector with more bindings dynamically.

ivankorobkov commented 6 years ago

Hi! Could you give examples when you need it?

All dependency injectors I know have a static configuration or modules, for example, Spring, Guice, Angular 2+, etc. Static modules 1) allow developers to reason about the application structure and interaction between components 2) are simpler to work with.

gshklover commented 6 years ago

Let say we are building a plugin-based framework. The framework itself provides a set of interfaces, which plugins require. But then when a plugin is loaded, it might provide additional interfaces used by other plugins later on.

ivankorobkov commented 6 years ago

I see. Python-inject is built to be immutable. It dramatically simplifies its internals: no need to worry about concurrency, thread-safety and performance.

In my opinion, you should better create a custom system to manage plugins. Of course, you can always fork the repository and tweak it to your needs. It's less then 400 hundred lines of code.