8000 GitHub - neetjn/python-inject-practice: Practice with python dependency injection using python-inject @ https://github.com/ivankorobkov/python-inject
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

neetjn/python-inject-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-inject-practice

Practice with python dependency injection using python-inject @ https://github.com/ivankorobkov/python-inject

This project was created to learn how to perform dependency injection, the pythonic way using python-inject. I'll be recording my thoughts and experiments in this repository.

Experiments

  • "instance" injection using python-inject. This injection strategy allows me to pull a binded dependency by object type from my injector given my configuration. See: instance_injection.py

  • "attribute" injection using python-inject. This injection strategy allows me to bind a dependency from my injector into class instances. See: attribute_injection.py

  • "param" injection using python-inject. This injection strategy allows me to inject dependencies into methods by param position or key. See: param_injection.py

What I've Learned

Preface: Until recently (3/1/2019) I've never knowingly used dependency injection. The design pattern was not something I was consciously aware of, however I leverage it almost daily in both personal projects and in production.

  • Dependency injection is more of a development pattern than anything else.
  • Contrary to my original confusion, there are multiple ways of tackling dependency injection.
  • Angular.js, which I've been actively using for the past couple of years, revolves around dependency injection:
    angular.module('myModule', [])
      .factory('serviceId', ['depService', depService => {
        // ...
      }])*
    
  • DI with python-inject can be very powerful with proper context control. IoC can also be incredibly helpful when using asynchronous code.

Resources


Copyright (c) 2019 John Nolette Licensed under the MIT License.

Releases

No releases published

Packages

No packages published

Languages

0