dixglobal

package
v0.3.21-alpha.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Container

func Container() dixinternal.Container

Container returns the global container instance

func Graph

func Graph() *dixinternal.Graph

Graph returns the dependency graph

func Inject

func Inject[T any](target T, opts ...dixinternal.Option) T

Inject 统一的依赖注入方法

支持多种注入目标类型:

  • 函数:解析参数并调用函数
  • 结构体指针:注入到结构体字段
  • 接口、切片、映射等其他类型

这个方法既可以注入依赖,也可以获取实例,提供统一的 API。

获取依赖实例的用法:

  • 获取单个依赖:var logger Logger; Inject(func(l Logger) { logger = l })
  • 获取多个依赖:var logger Logger; var db *DB; Inject(func(l Logger, d *DB) { logger, db = l, d })

参数:

  • target: 注入目标(函数、结构体指针等)
  • opts: 可选配置

func Provide

func Provide(provider any)

Provide registers an object constructor

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL