Getting Started¶
Installation¶
Install dijay using your preferred package manager:
Python Version
dijay requires Python 3.13+ and leverages modern features like type parameter syntax and Annotated generics.
Your First App¶
1. Define a Service¶
Use the @injectable decorator to mark a class as injectable:
from dijay import injectable
@injectable()
class GreetingService:
def greet(self, name: str) -> str:
return f"Hello, {name}!"
2. Create a Module¶
Modules group related providers together. Use providers to register and exports to share:
from dijay import module
@module(
providers=[GreetingService],
exports=[GreetingService],
)
class GreetingModule: ...
3. Create the Root Module¶
The root module imports all feature modules:
4. Bootstrap and Resolve¶
Use Container.from_module to build the dependency graph and resolve services:
import asyncio
from dijay import Container
async def main():
async with Container.from_module(AppModule) as container:
service = await container.resolve(GreetingService)
print(service.greet("World"))
if __name__ == "__main__":
asyncio.run(main())
Running this will print:
How It Works¶
@injectable()marksGreetingServiceas a provider.@module(...)groups providers and exports them.Container.from_module(AppModule)scans the module tree and registers all providers.async with containerruns@module.on_bootstraphooks on entry and@module.on_shutdownhooks on exit.container.resolve(GreetingService)returns a fully constructed instance with all dependencies injected.
Next Steps¶
- Learn how to organize your app with Modules
- Use Custom Providers for values, factories, and class overrides
- Add Lifecycle Hooks for startup/shutdown logic
- Integrate with FastAPI