Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions fastapi_startkit/src/fastapi_startkit/container/container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Core of the IOC Container."""

import inspect
from typing import Any

from ..exceptions import (
ContainerError,
Expand Down Expand Up @@ -42,15 +43,12 @@ def __init__(self):
self.swaps = {}
self._remembered = {}

def bind(self, name, class_obj):
def bind(self, name: str, class_obj: Any) -> None:
"""Bind classes into the container with a key value pair.

Arguments:
name {string} -- Name of the key you want to bind the object to
class_obj {object} -- The object you want to bind

Returns:
self
"""
if inspect.ismodule(class_obj):
raise StrictContainerException(
Expand All @@ -63,8 +61,6 @@ def bind(self, name, class_obj):
self.fire_hook("bind", name, class_obj)
self.objects.update({name: class_obj})

return self

def unbind(self, name):
"""Unbind classes from the container from a key.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

if TYPE_CHECKING:
from fastapi_startkit.application import Application
from fastapi_startkit.config import AppConfig


class Provider:
provider_key: str = None

def __init__(self, application: "Application", config: dict = None):
self.app: "Application" = application
def __init__(self, application: "Application[AppConfig]", config: dict = None):
self.app: "Application[AppConfig]" = application
self.config = config or {}

if self.provider_key is None:
Expand Down
4 changes: 2 additions & 2 deletions fastapi_startkit/tests/core/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def test_bind_and_make_object_instance(self, container):
container.bind("service_a", svc)
assert container.make("service_a") is svc

def test_bind_returns_self_for_chaining(self, container):
def test_bind_returns_none(self, container):
result = container.bind("x", 42)
assert result is container
assert result is None

def test_bind_overrides_existing_key_by_default(self, container):
container.bind("key", "first")
Expand Down
Loading