8000 GitHub - FosterToster/simple_di: Simple Python Dependency injector. Inspired by Dependency Injector.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simple Python Dependency injector. Inspired by Dependency Injector.

Notifications You must be signed in to change notification settings

FosterToster/simple_di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple dependency injection

It keeps intellisense and doesn't needs any wirings/decorators

New container exapmle:

# base class for containers
from simple_di import BaseContainer

# Some providers
from simple_di import Singletone, Factory, Dummy

# Note that providers are working only with classes.
# Do not try to use primitive types as container values

# Test class
class Some:
    def __init__(self, args):
        ...

class App(BaseContainer):


    # Singletone DI provider guarantees that "Some" 
    # will be instanced once with passed args/kwargs 
    # and the same instance will be available for each dependency usage
    some = Singletone(Some, "hello", "world") 


    # Factory DI provider will create new instance of "Some" 
    # with passed args/kwargs each time when dependency will be used
    more = Factory(Some, "hello", "world")

    # Dummy provider just requires to be overriden.
    # Passed type will be never instanced, but will be used for intellisense.
    much_more = Dummy(Some)

Container usage example

# with function
def some_frequently_referenced_func(required_arg, *, required_kwarg, dependency = App.some):
    # intellisense for "dependency" will work here.
    ...

# with classes
class SomeController:
    def __init__(self, dependency = App.more):
        self.dep = dependency

About

Simple Python Dependency injector. Inspired by Dependency Injector.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0