Skip to content

Releases: KuyuCode/fundi

v1.6.1

12 Mar 12:23
91a7238

Choose a tag to compare

What's Changed

  • Fix documentation for Scope value resolving by type by @kuyugama in #66

Full Changelog: v1.6.0...v1.6.1

V1.6.0 | Scope as a class

12 Mar 11:36
2aa8d1c

Choose a tag to compare

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

Full Changelog: v1.5.0...v1.6.0

v1.5.0 | GPL -> LGPL license

11 Nov 21:14
bca6f9b

Choose a tag to compare

What's Changed

Full Changelog: v1.4.1...v1.5.0

v1.4.1

09 Nov 18:11
d10c899

Choose a tag to compare

What's Changed

  • Fix side-effect binding scope collision at first callable scan by @kuyugama in #58

Full Changelog: v1.4.0...v1.4.1

v1.4.0 | Python 3.14, side effects and scope hook

09 Nov 17:16
3bcc562

Choose a tag to compare

What's Changed

Full Changelog: v1.3.7...v1.4.0

v1.3.7

10 Oct 17:56
0d8d65f

Choose a tag to compare

Full Changelog: v1.3.6...v1.3.7

v1.3.5 | Optional Exit Stack

10 Oct 17:45
b8d04c6

Choose a tag to compare

What's Changed

  • Make stack parameter optional in [a]inject() function by @kuyugama in #51

Full Changelog: v1.3.4...v1.3.5

v1.3.4 | Graph hook

10 Oct 07:10
e73d126

Choose a tag to compare

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

13 Sep 00:56
8c7323c

Choose a tag to compare

What's Changed

  • Add support of defining dependencies using typing.Annotated by @kuyugama in #47

Full Changelog: v1.3.2...v1.3.3

v1.3.2

12 Sep 01:47
be626bd

Choose a tag to compare

What's Changed

  • If normalize_annotation returned non-type value use its type by @kuyugama in #46

Full Changelog: v1.3.1...v1.3.2