Socket
Book a DemoInstallSign in
Socket

@braken/injection

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@braken/injection

somethings

latest
npmnpm
Version
1.1.32
Version published
Maintainers
1
Created
Source

@braken/injection

Braken 框架的依赖注入模块,提供 IoC 容器和依赖注入支持。

安装

pnpm add @braken/injection

特性

  • 依赖注入容器
  • 装饰器支持
  • 生命周期管理
  • 作用域管理
  • 循环依赖处理
  • 动态注入

使用示例

import { Injectable, Inject } from '@braken/injection';

@Injectable()
class UserService {
  @Inject()
  private logger: Logger;

  async findUser(id: string) {
    this.logger.info('Finding user', { id });
    // 查找用户逻辑
  }
}

@Injectable()
class UserController {
  @Inject()
  private userService: UserService;

  async getUser(id: string) {
    return this.userService.findUser(id);
  }
}

API

装饰器

  • @Injectable: 标记可注入类
  • @Inject: 注入依赖
  • @Optional: 标记可选依赖
  • @Scope: 定义作用域
  • @PostConstruct: 构造后回调
  • @PreDestroy: 销毁前回调

容器

import { Container } from '@braken/injection';

const container = new Container();

// 注册服务
container.register(UserService);
container.register(UserController);

// 获取实例
const userController = container.get(UserController);

许可证

MIT

FAQs

Package last updated on 09 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts