Repository navigation
Bevy 3.1.0-beta.10
Pre-release
Pre-release
·
12 commits
to main
since this release
Bevy 3.1.0-beta.10 Release 馃殌
馃専 Major Features
Async-Native Dependency Resolution with find() and Result
- New
container.find()method: Returns aResult[T]type that can be resolved in sync or async contexts Resulttype: Deferred dependency resolution with.get()(sync) and.get_async()(async) methods- Benefit: Truly async-native dependency resolution with no thread overhead in async code
Async Function Injection
- Automatic async detection:
@injectableasync functions work seamlessly withcontainer.call() - Async-native injection: Dependencies are resolved using
await container.find()automatically - Benefit: Write async functions with dependency injection just like sync functions
Async-Native Hook Architecture
- Removed sync wrappers: Hooks now execute in native async context when using
find() - Real async work: Async hooks can perform I/O, delays, and other async operations efficiently
- Benefit: No unnecessary thread spawning when working in async contexts
馃敡 Technical Improvements
Hook System
- Async-first execution:
HookManager.handle()andHookManager.filter()are now purely async - Sync compatibility: Sync hooks still work - automatically called within async context
- Pattern matching: Use match/case instead of isinstance for Optional checks
Container API
- Read-only
parentproperty: Clean API for accessing parent containers - Removed dead code: Cleaned up unused
_create_instanceand_call_post_injection_hookmethods
馃摎 Documentation Updates
- New Section: "Async-Native Dependency Resolution" in usage guide with best practices
- API Reference: Complete documentation for
Resulttype andfind()method - Hook Reference: Updated to clarify which hooks work in async-native architecture
- Best Practices: Added guidance on using
await container.find(T)instead ofcontainer.get(T)in async code
馃И Testing & Quality
Test Coverage
- 7 new async function injection tests: Covering async functions with hooks, qualifiers, and factories
- Async hook verification: Tests confirm async hooks run in same async context (no thread overhead)
- Total: 179 tests passing (up from 172)
馃挕 Usage Examples
Async-Native Dependency Resolution:
from bevy import injectable, Inject, get_container
# In async code - truly async with no thread overhead
async def process_order(order_id: str):
container = get_container()
db = await container.find(Database)
cache = await container.find(Cache, qualifier="redis")
user = await db.get_user(order_id)
await cache.set(f"user:{order_id}", user)
# Async function injection
@injectable
async def send_notification(
user_id: str,
email: Inject[EmailService],
db: Inject[Database]
):
user = await db.get_user(user_id)
await email.send(user.email, "Welcome!")
# Call it - returns a coroutine
container = get_container()
await container.call(send_notification, user_id="123")Result Type:
# Get a Result for deferred resolution
result = container.find(Service)
# Resolve in async context - no thread overhead
instance = await result # Uses __await__
# OR
instance = await result.get_async()
# Resolve in sync context - runs async in thread
instance = result.get()鈿狅笍 Breaking Changes
Injection Lifecycle Hooks (Minor Impact)
The following hooks are no longer called from sync container.call() in the async-native architecture:
INJECTION_REQUESTINJECTION_RESPONSEPOST_INJECTION_CALLMISSING_INJECTABLEFACTORY_MISSING_TYPE
Migration: Use dependency resolution hooks instead (GET_INSTANCE, GOT_INSTANCE, CREATE_INSTANCE, CREATED_INSTANCE, HANDLE_UNSUPPORTED_DEPENDENCY), which work in both sync and async contexts.
Impact: Low - these hooks were primarily used for observability, and most users don't use them.
馃檹 Acknowledgments
Thank you to all contributors who made this release possible!
Full Changelog: View on GitHub
Installation: pip install bevy==3.1.0-beta.10
Feedback: Please report any issues or feedback on our GitHub Issues page.