---
title: dependency | CodeWeaver Docs
description: API reference for codeweaver.core.di.dependency
url: "https://docs.knitli.com/api/core/di/dependency"
type: static
generatedAt: "2026-04-17T17:21:07.994Z"
---

# dependency
       [Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F.%20I%20want%20to%20ask%20questions%20about%20it.)[View in Markdown](/codeweaver/api/core/di/dependency.md)       [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F)[Share on X](https://x.com/intent/tweet?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F&text=dependency)[Share on Threads](https://threads.net/intent/post?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F&text=dependency)[Share on Bluesky](https://bsky.app/intent/compose?text=dependency%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F)[Share on Reddit](https://reddit.com/submit?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F&title=dependency)[Share on Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F&t=dependency)[Share on Email](mailto:?subject=dependency&body=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F)[Share on WhatsApp](https://wa.me/?text=dependency%20https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F)[Share on Telegram](https://t.me/share/url?url=https%3A%2F%2Fdocs.knitli.com%2Fcodeweaver%2Fapi%2Fcore%2Fdi%2Fdependency%2F&text=dependency)
# `codeweaver.core.di.dependency`
[Section titled “codeweaver.core.di.dependency”](#codeweavercoredidependency)
Dependency marker for declarative injection.

## Class: `Depends`
[Section titled “Class: Depends”](#class-depends)
Dependency marker, inspired by FastAPI.

Marks a parameter for dependency injection by the DI container.

## Basic Usage (Auto-Resolution)
[Section titled “Basic Usage (Auto-Resolution)”](#basic-usage-auto-resolution)
The simplest approach is to use the INJECTED sentinel with a type annotation:


**

```
from codeweaver.core.di import INJECTED, dependency_provider

@dependency_provider(scope="singleton")class ServiceProvider:    def __init__(self):        self.value = 42

async def my_function(service: ServiceProvider = INJECTED) -&gt; None:    # service is automatically injected based on the type annotation    print(service.value)
```

## Advanced Usage (Explicit Factory)
[Section titled “Advanced Usage (Explicit Factory)”](#advanced-usage-explicit-factory)
For more control, use the Depends marker with an explicit factory:


**

```
from typing import Annotatedfrom codeweaver.core.di import Depends, INJECTED, dependency_provider

@dependency_provider(ServiceProvider)async def service_factory() -&gt; ServiceProvider:    # Custom initialization logic here    return ServiceProvider()

async def my_function(    service: Annotated[ServiceProvider, Depends(service_factory)] = INJECTED,) -&gt; None:    print(service.value)
```

## Scope Control
[Section titled “Scope Control”](#scope-control)
Control caching behavior with the `scope` parameter:


**

```
from typing import Annotatedfrom codeweaver.core.di import depends, INJECTED
# Singleton: one instance per application lifetimetype SingletonService = Annotated[Service, depends(scope="singleton")]
# Request: one instance per requesttype RequestService = Annotated[Service, depends(scope="request")]
# Function: new instance every time (no caching)type FunctionService = Annotated[Service, depends(scope="function")]

async def handler(    singleton: SingletonService = INJECTED,    request: RequestService = INJECTED,    fresh: FunctionService = INJECTED,) -&gt; None: ...
```

## Type Aliases for Clean Code
[Section titled “Type Aliases for Clean Code”](#type-aliases-for-clean-code)
Create type aliases to avoid repeating Annotated everywhere:


**

```
from typing import TYPE_CHECKING, Annotatedfrom codeweaver.core.di import INJECTED, depends
if TYPE_CHECKING:    from someplace import ServiceProvider
# Simple alias (uses default singleton scope)type ServiceDep = ServiceProvider
# Or with explicit behaviortype RequestScopedService = Annotated[ServiceProvider, depends(scope="request")]

async def my_function(service: RequestScopedService = INJECTED) -&gt; None:    # service will be injected with request scope    ...
```

## Class: `DependsPlaceholder`
[Section titled “Class: DependsPlaceholder”](#class-dependsplaceholder)
Indicates that a parameter’s value should be injected by the DI container.

Supports type-safe usage via subscript syntax to satisfy type checkers while maintaining sentinel behavior at runtime.

Usage:

# Type-safe with subscript (recommended):
[Section titled “Type-safe with subscript (recommended):”](#type-safe-with-subscript-recommended)
async def my_function( embedding: Annotated[EmbeddingProvider, Depends(get_embedding)] = INJECTED ) -> None:

# embedding will be injected by the container
[Section titled “embedding will be injected by the container”](#embedding-will-be-injected-by-the-container)
…

# Or with type alias:
[Section titled “Or with type alias:”](#or-with-type-alias)
async def my_function( embedding: EmbeddingDep = INJECTED ) -> None: …

## Function: `depends`
[Section titled “Function: depends”](#function-depends)

**

```
depends()
```

Helper function to create a Depends marker.

## Function: `is_depends_marker`
[Section titled “Function: is_depends_marker”](#function-is_depends_marker)

**

```
is_depends_marker()
```

Check if a value is a DI injection marker or sentinel.

Handles Depends markers, DependsPlaceholder sentinels, and the INJECTED proxy.