# microsoft/tsyringe architecture

> Architecture diagram of the GitHub repository microsoft/tsyringe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/tsyringe
- Repository: https://github.com/microsoft/tsyringe

## Overview

##### Main Components

a) Core Container System:
- DependencyContainer (central component)
- Registry System
- Resolution System
- Child Container System

b) Decorator System:
- Injectable Decorator
- Singleton Decorator
- AutoInjectable Decorator
- Inject Decorator
- Registry Decorator
- Scoped Decorator

c) Provider System:
- Class Provider
- Value Provider
- Factory Provider
- Token Provider

d) Supporting Systems:
- Reflection System
- Error Handling System
- Lifecycle Management
- Interception System

##### Specific Implementation Details

Create distinct sections for:
a) Registration Flow:
- How @injectable and other decorators register with container
- Demonstrate registry flow for different provider types

b) Resolution Flow:
- Dependency resolution process
- Circular dependency handling with delay function
- Singleton vs transient lifecycle management

- Decorator Layer    |

- Container Layer    |

- Provider Layer     |

- Support Layer      |

##### Important Details to Highlight

- Circular dependency resolution mechanism
- Scoping levels (Singleton, Transient, ContainerScoped)
- Interception points (beforeResolution, afterResolution)
- Instance caching strategy
- Reflection metadata usage

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#b3d1ff,stroke:#333
    classDef decorator fill:#98fb98,stroke:#333
    classDef provider fill:#fff59d,stroke:#333
    classDef support fill:#e0e0e0,stroke:#333
    classDef factory fill:#ffcc80,stroke:#333

    %% Decorator Layer
    subgraph Decorators
        Injectable["@Injectable()"]:::decorator
        Singleton["@Singleton()"]:::decorator
        AutoInject["@AutoInjectable()"]:::decorator
        Inject["@Inject()"]:::decorator
        Registry["@Registry()"]:::decorator
        Scoped["@Scoped()"]:::decorator
    end

    %% Core Container Layer
    subgraph Container
        DependencyContainer["DependencyContainer"]:::core
        RegistrySystem["Registry System"]:::core
        ResolutionSystem["Resolution System"]:::core
        ChildContainer["Child Container System"]:::core
    end

    %% Provider Layer
    subgraph Providers
        ClassProvider["Class Provider"]:::provider
        ValueProvider["Value Provider"]:::provider
        FactoryProvider["Factory Provider"]:::provider
        TokenProvider["Token Provider"]:::provider
        BaseProvider["Provider Interface"]:::provider
    end

    %% Support Layer
    subgraph Support
        Reflection["Reflection System"]:::support
        ErrorHandling["Error Handling"]:::support
        Lifecycle["Lifecycle Management"]:::support
        Interception["Interception System"]:::support
    end

    %% Factory Layer
    subgraph Factories
        InstanceCache["Instance Caching"]:::factory
        ContainerCache["Container Caching"]:::factory
        PredicateFactory["Predicate Factory"]:::factory
    end

    %% Relationships
    Injectable --> DependencyContainer
    Singleton --> DependencyContainer
    AutoInject --> DependencyContainer
    Inject --> DependencyContainer
    Registry --> RegistrySystem
    Scoped --> Lifecycle

    DependencyContainer <--> RegistrySystem
    DependencyContainer <--> ResolutionSystem
    DependencyContainer <--> ChildContainer
    DependencyContainer <--> Providers
    
    ResolutionSystem --> Providers
    Lifecycle --> ResolutionSystem
    Interception --> ResolutionSystem
    
    Providers --> InstanceCache
    Providers --> ContainerCache
    Providers --> PredicateFactory

    %% Click Events
    click DependencyContainer "https://github.com/microsoft/tsyringe/blob/master/src/dependency-container.ts"
    click RegistrySystem "https://github.com/microsoft/tsyringe/blob/master/src/registry.ts"
    click ResolutionSystem "https://github.com/microsoft/tsyringe/blob/master/src/resolution-context.ts"
    click ChildContainer "https://github.com/microsoft/tsyringe/blob/master/src/__tests__/child-container.test.ts"
    
    click Injectable "https://github.com/microsoft/tsyringe/blob/master/src/decorators/injectable.ts"
    click Singleton "https://github.com/microsoft/tsyringe/blob/master/src/decorators/singleton.ts"
    click AutoInject "https://github.com/microsoft/tsyringe/blob/master/src/decorators/auto-injectable.ts"
    click Inject "https://github.com/microsoft/tsyringe/blob/master/src/decorators/inject.ts"
    click Registry "https://github.com/microsoft/tsyringe/blob/master/src/decorators/registry.ts"
    click Scoped "https://github.com/microsoft/tsyringe/blob/master/src/decorators/scoped.ts"
    
    click ClassProvider "https://github.com/microsoft/tsyringe/blob/master/src/providers/class-provider.ts"
    click ValueProvider "https://github.com/microsoft/tsyringe/blob/master/src/providers/value-provider.ts"
    click FactoryProvider "https://github.com/microsoft/tsyringe/blob/master/src/providers/factory-provider.ts"
    click TokenProvider "https://github.com/microsoft/tsyringe/blob/master/src/providers/token-provider.ts"
    click BaseProvider "https://github.com/microsoft/tsyringe/blob/master/src/providers/provider.ts"
    
    click Reflection "https://github.com/microsoft/tsyringe/blob/master/src/reflection-helpers.ts"
    click ErrorHandling "https://github.com/microsoft/tsyringe/blob/master/src/error-helpers.ts"
    click Lifecycle "https://github.com/microsoft/tsyringe/blob/master/src/types/lifecycle.ts"
    click Interception "https://github.com/microsoft/tsyringe/blob/master/src/interceptors.ts"
    
    click InstanceCache "https://github.com/microsoft/tsyringe/blob/master/src/factories/instance-caching-factory.ts"
    click ContainerCache "https://github.com/microsoft/tsyringe/blob/master/src/factories/instance-per-container-caching-factory.ts"
    click PredicateFactory "https://github.com/microsoft/tsyringe/blob/master/src/factories/predicate-aware-class-factory.ts"
```
