Skip to main content

Injector support in nameko

Project description

injector based dependency injection mechanism for the nameko services. Project is similar to flask-injector.

Problem

Nameko provides a dependency injection mechanism, built-in in the framework. It works in many cases but there are limitations:

  1. All the dependencies are injected regardless of whether they are used in the entry-point. For instance, all the dependencies will be injected for /health HTTP entry point.
  2. Dependencies cannot depend on each other.
  3. The scope is an implementation detail. Frequency of the dependency creation depends on the DependencyProvider implementation.

Solution

The library provides an alternative dependency injection mechanism to the one that is built-in in nameko. Several types of request scope can be used out of the box without special injector module declarations.

  • nameko_injector.core.ServiceConfig
  • from nameko.containers.ServiceContainer
  • from nameko.containers.WorkerContext

An example:

import json
from nameko_injector.core import NamekoInjector, ServiceConfig
from nameko.web.handlers import http


INJECTOR = NamekoInjector()

@INJECTOR.decorate_service
class Service:

  name = 'service-name'

  @http('GET', '/health')
  def health(self, request):
     return {'status': 'ok'}

  @http('GET', '/config')
  def view_config(self, request, config: ServiceConfig):
    return json.dumps(config)

Development

tox

TODO

  • testing: Add the tests for RPC entry points
  • document testing with the library

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for nameko-injector, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size nameko-injector-0.1.2.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page