Skip to content

Transient or Scoped dependency support #65

@sparky2708

Description

@sparky2708

Is there a way to implement transient or scoped dependency? I am thinking of a way to create services that would only exist for the life of the api request in FastApi. E.g. let’s say you get a message with 2 different sections:

[
{trees: [ {tree: {id: 1, desc: “pine”}, …]
{dogs: [ {dog: {id: 1, name: “potato”}, …]
]

When I receive this message I want to use a TreeProvider and DogProvider that source their data from the above message and can be injected just for processing that request and not for other requests.

@inject() #message will be injected
def class DogProvider(IDogProvider):
     def __init__(self, message):
          …

     def get_dogs() -> Dog:
          …

@inject() #message will be injected
def class TreeProvider(ITreeProvider):
     def __init__(self, message)
          …

     def get_trees() -> Tree:
          …

This is similar to a C# scoped or transient registration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions