Skip to content

A thoughtful dependency injection framework 💉

License

Notifications You must be signed in to change notification settings

ZeroGachis/nurse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nurse

Outline

  1. Overview
  2. Installation
  3. Usage
  4. License

Overview

Nurse is a dependency injection framework with a small API that uses type annotations to manage dependencies in your codebase.

Installation

Nurse is a Python3-only module that you can install via Poetry

poetry add nurse

It can also be installed with pip

pip3 install nurse

Usage

Nurse stores the available dependencies into a service catalog, that needs to be filled-in generally at the startup of your application.

import nurse

# A user defined class that will be used accross your application
class Player:

    def name(self, name) -> str:
        return "John Doe"

# Now, add it to nurse service catalog in order to use it later in your application
nurse.serve(Player())

Nurse allows you to abstract dependencies through an optional name parameter allowing you to refer your class instance through its interface.

import nurse

# A user defined class that will be used accross your application
class Player(User):

    def name(self) -> str:
        return "John Doe"

# Now, add it to nurse service catalog in order to use it later in your application
nurse.serve(Player(), name=User)

Once you filled-in the service catalog with your different component, your can declare them as dependencies to any of your class.

import nurse

@nurse.inject
class Game:
    player: Player

    def response(self) -> str:
        return f"Hello {self.player.name()} !"


Game = Game()
game.response()
# Hello John Doe !

License

Nurse is released into the Public Domain. 🎉

About

A thoughtful dependency injection framework 💉

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published