Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/neetjn/python-inject-practice

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

dependency dependency-injection inject python python-inject

Last synced: 12 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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**](https://github.com/ivankorobkov/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](https://github.com/neetjn/python-inject-practice/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](https://github.com/neetjn/python-inject-practice/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](https://github.com/neetjn/python-inject-practice/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

* Wikipedia (Dependency injection) - https://en.wikipedia.org/wiki/Dependency_injection
* baeldung (IoC and Dependency Injection in Spring) - https://www.baeldung.com/inversion-control-and-dependency-injection-in-spring
* angularjs/docs - https://docs.angularjs.org/guide/di
* pinject - https://github.com/google/pinject
* preslav (Dependency Injection In Python - The Java Guy's Perspective) - https://preslav.me/2018/12/20/dependency-injection-in-python/

___

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