Releases: KuyuCode/fundi
v1.6.1
V1.6.0 | Scope as a class
New Feature: Scope object and Type Factories
This release introduces the new Scope class, which is intended as a more structured and powerful replacement for the plain, dictionary-based scopes used previously.
Scope Class
The Scope object provides a formal structure for defining dependencies, including named values, typed instances, and the new type factories.
To ensure backward compatibility, your existing code will continue to work as expected. Legacy dictionary-based scopes are automatically converted into Scope objects using the Scope.from_legacy method, so no changes are required for your existing implementations.
New Feature: Type Factories
This change also adds a completely new feature to fundi: Type Factories.
Type factories allow you to define a factory for a specific type, which will be executed on-demand whenever an instance of that type is required by a dependency.
Here is an example:
from fundi import Scope, inject
class UserService:
def get_user(self, user_id: int) -> str:
# In a real app, this would query a database
return f"User_{user_id}"
# This factory will be called anytime a `UserService` is needed
def create_user_service() -> UserService:
return UserService()
# Create a scope and add the factory
scope = Scope()
scope.add_factory(create_user_service)
# A dependant that needs `UserService`
def get_username(user_id: int, service: UserService) -> str:
return service.get_user(user_id)
# `create_user_service` is called automatically inside `inject`
username = inject(scope, get_username, {"user_id": 1})
assert username == "User_1"Important Note: Type factories provide an implicit way to define dependencies. While powerful, they should be used judiciously. For core application components and clearer dependency graphs, explicitly defining dependencies is often preferred.
What's Changed
- Configure ty and ruff for the project by @kuyugama in #63
- Improve
from_(...)overloads for generators by @kuyugama in #64 - Injection scope as a class by @kuyugama in #65
Full Changelog: v1.5.0...v1.6.0
v1.5.0 | GPL -> LGPL license
v1.4.1
v1.4.0 | Python 3.14, side effects and scope hook
v1.3.7
Full Changelog: v1.3.6...v1.3.7
v1.3.5 | Optional Exit Stack
What's Changed
Full Changelog: v1.3.4...v1.3.5
v1.3.4 | Graph hook
What's Changed
- Disable caching of the parameter-aware dependencies by default by @kuyugama in #48
- Revert "Disable caching of the parameter-aware dependencies by default" by @kuyugama in #50
- Add hook that is called when dependency is defined in dependant by @kuyugama in #49
Full Changelog: v1.3.3...v1.3.4
v1.3.3 | Dependencies inside typing.Annotated
What's Changed
Full Changelog: v1.3.2...v1.3.3