I am busy programming a microservice backend in Python using Nameko. While searching for a good dependency injection package I came a across Injector. I really liked it and wanted to use it together with Nameko. Then I noticed a small problem: Nameko instantiates the workers and doesn't work with dependency injection packages out of the box. After trying to get it to work using the documentation I stumbled upon the package nameko-injector. I liked the concept and tried to implement it but i get the error:
Parameter 'bindings' unfilled
Using the example code from the git repository (shown below) the problem occurred at the initialization of the NamekoInjector class.
The microservice worker class:
from nameko.rpc import rpc
from services.order_service import OrderService
from nameko_injector.core import NamekoInjector
INJECTOR = NamekoInjector()
@INJECTOR.decorate_service
class OrderWorker:
# Mandatory field for service discovery
name = "order_worker"
def __init__(self, service: OrderService):
self.service = service
@rpc
def get_orders(self):
return self.service.orders()
The OrderService class:
from models.order.order import Order
class OrderService(object):
def __init__(self):
self.orders = [Order(1), Order(2)]
def get_users(self):
return self.orders
The Order class:
class Order:
def __init__(self, orderid):
self.orderid = orderid
def __str__(self):
return str(self.orderid)
When looking in the NamekoInjector class I couldn't find out what the binding exactly does and when it's used. In the first place I don't even need it but when I delete the binding fields and other usages in the NamekoInjector class, it still won't work. Can anybody please help me? Thanks!