Skip to content

A thoughtful dependency injection framework ๐Ÿ’‰

License

Notifications You must be signed in to change notification settings

ZeroGachis/nurse

Repository files navigation

Nurse ๐Ÿ’‰

Nurse is a small dependency injection library.

Usage

Nurse stores the services into a service catalog that needs to be filled-in generally at the edge of your application.

To serve a singleton instance of your service:

import nurse

class Animal:
    def make_noise(self) -> str:
        return "..."

class AngryAnimal(Animal):
    def make_noise(self) -> str:
        return "Grrr! ๐Ÿฆ"


nurse.serve(Animal, singleton=AngryAnimal())

animal = nurse.get(Animal)
animal.make_noise()
# "Grrr! ๐Ÿฆ"

To serve a new instance of your service each time it's being retrieved:

import nurse

class Animal:
    def make_noise(self) -> str:
        return "..."

class AngryAnimal(Animal):
    def make_noise(self) -> str:
        return "Grrr! ๐Ÿฆ"


nurse.serve(Animal, factory=AngryAnimal)

animal = nurse.get(Animal)
animal.make_noise()
# "Grrr! ๐Ÿฆ"

About

A thoughtful dependency injection framework ๐Ÿ’‰

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7