tombulled / needle

Dependency Injection for Python
MIT License
0 stars 0 forks source link

:sparkles: Automatically Create Sequences of Dependencies #6

Open tombulled opened 1 year ago

tombulled commented 1 year ago

Pseudocode:

@dataclass
class Animal:
    name: str

class Dog(Animal):
    pass

class Cat(Animal):
    pass

@bean
def dog() -> Dog:
    return Dog("Baxter")

@bean
def cat() -> Cat:
    return Cat("Biscuit")

>>> resolve(List[Animal])
[Dog("Baxter"), Cat("Biscuit")]
tombulled commented 1 year ago

Maybe, as a solution to this, have some generic dependencies that are always available, e.g:

@bean
def generic_list(*items: T) -> List[T]:
    return list(items)

@bean
def generic_sequence(*items: T) -> Sequence[T]:
    return items

etc.