定制 pedhot-dev/nepotismfree-di-autowire 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pedhot-dev/nepotismfree-di-autowire

Composer 安装命令:

composer require pedhot-dev/nepotismfree-di-autowire

包简介

An optional Autowire / Resolver layer for NepotismFree-DI. Strict DI stays strict; this resolver sits on top.

README 文档

README

NepotismFree Autowire is an optional reflection-based resolution layer for the strict NepotismFree-DI container.

It allows you to resolve concrete classes and inject dependencies automatically using attributes, without compromising the strict, nepotism-free philosophy of the core container.

Philosophy

  1. Strict DI Stays Strict: This library does not modify the core container. The container remains immutable, explicit, and dumb (in a good way).
  2. Autowire is NOT a Container: It is a resolver. It uses the container to fetch defined services but instantiates undefined concrete classes on the fly.
  3. Opt-In Complexity: Reflection is only used when you explicitly ask for it via the Autowire facade.

Installation

composer require pedhot-dev/nepotismfree-di-autowire

Basic Usage

Wrap your strict container with the Autowire resolver.

use PedhotDev\NepotismFree\Core\NepotismFree;
use PedhotDev\NepotismFree\Autowire\Autowire;
use PedhotDev\NepotismFree\Autowire\AutowireResolver;

// 1. Build your strict container (Definitions & Singletons)
$builder = NepotismFree::createBuilder();
$builder->bind(Database::class, fn() => new Database(...));
$container = $builder->build();

// 2. Wrap it with Autowire
$resolver = new AutowireResolver($container);
$autowire = new Autowire($resolver);

// 3. Resolve!
// 'UserController' is NOT in the container, but Autowire creates it 
// and injects 'Database' from the strict container.
$controller = $autowire->resolve(UserController::class);

Attributes

You can control injection logic using PHP Attributes.

Attribute Description Example
#[FromContainer] Inject a specific service ID from the strict container. #[FromContainer('db.read')]
#[FromEnv] Inject a value from environment variables. #[FromEnv('API_KEY')]
#[FromValue] Inject a raw/scalar value directly. #[FromValue(100)]

Architecture: Facade vs. Resolver

We separate Login from Ergonomics.

  • AutowireResolver: The brain. Contains all reflection logic, attribute parsing, and recursion.
  • Autowire: The face. A simple facade that forwards calls to the resolver.

You will almost always use the Autowire facade in your application.

What this library does NOT do

  • It does NOT auto-register services.
    • Resolved instances are not stored back into the container.
    • If you resolve MyService twice, you get two new instances (unless it's explicitly bound as a singleton in the underlying container).
  • It does NOT implement ContainerInterface.
    • It is a tool for resolving, not for storing.
  • It does NOT support "magic" binding.
    • There is no bind() method on the Autowire layer. Bindings belong in the strict container. Autowire just reads them.

When to use?

  • Use Strict Container for: Core infrastructure, specific implementations of interfaces, singletons, and reusable services.
  • Use Autowire for: Controllers, Jobs, Commands, and "leaf" nodes of your application that have many dependencies but don't need to be shared.

pedhot-dev/nepotismfree-di-autowire 适用场景与选型建议

pedhot-dev/nepotismfree-di-autowire 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 pedhot-dev/nepotismfree-di-autowire 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pedhot-dev/nepotismfree-di-autowire 我们能提供哪些服务?
定制开发 / 二次开发

基于 pedhot-dev/nepotismfree-di-autowire 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 35
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08