implement lightweight IOC/DI framework

- Add annotation system (@Component, @Service, @Configuration, @Bean, @Inject, @Qualifier, @Primary, @Scope, @PostConstruct, @Import, @TimiInjectApplication)
- Implement BeanContext for managing bean instances and definitions
- Implement BeanScanner for component scanning (file system and jar)
- Implement BeanFactory with constructor injection and lifecycle support
- Support @Configuration and @Bean factory methods
- Support @Qualifier and @Primary for multi-implementation
- Support @Scope (singleton/prototype)
- Support @PostConstruct lifecycle callback
- Support @Import and Module extension
- Add circular dependency detection
- Add dependency graph export
- Add demo and test cases

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Timi
2026-01-11 12:26:14 +08:00
parent 05606eda74
commit 71be7c07c0
43 changed files with 1429 additions and 1129 deletions

View File

@ -0,0 +1,28 @@
package com.imyeyu.inject.demo;
import com.imyeyu.inject.annotation.PostConstruct;
import com.imyeyu.inject.annotation.Service;
/**
* 用户服务
*
* @author 夜雨
*/
@Service
public class UserService {
private final UserRepository repository;
public UserService(UserRepository repository) {
this.repository = repository;
}
@PostConstruct
public void init() {
System.out.println("UserService initialized");
}
public String hello() {
return "Hello from UserService! Repository: " + repository.getClass().getSimpleName();
}
}