Skip to content

Commit

Permalink
🐳 #386 Action supports constructor injection with parameters in Spring
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed Oct 21, 2024
1 parent 185c603 commit e3abc36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
public final class ActionCommand {
/** cmdInfo */
final CmdInfo cmdInfo;
/** 构造方法访问器 */
final ConstructorAccess<?> actionControllerConstructorAccess;

/** 一个single控制器对象 */
final Object actionController;
/** 方法所在 class */
Expand Down Expand Up @@ -98,14 +97,15 @@ public final class ActionCommand {

/** true 表示交付给容器来管理 如 spring 等 */
boolean deliveryContainer;
/** 构造方法访问器 */
ConstructorAccess<?> actionControllerConstructorAccess;

private ActionCommand(Builder builder) {
// -------------- 路由相关 --------------
this.cmdInfo = CmdInfoFlyweightFactory.of(builder.cmd, builder.subCmd);

// -------------- 控制器相关 --------------
this.actionControllerClazz = builder.actionControllerClazz;
this.actionControllerConstructorAccess = builder.actionControllerConstructorAccess;
this.actionController = builder.actionController;
this.createSingleActionCommandController = builder.createSingleActionCommandController;

Expand Down Expand Up @@ -153,6 +153,20 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return actionMethod.getAnnotation(annotationClass);
}

/**
* get class ConstructorAccess
*
* @return ConstructorAccess
* @since 21.19
*/
public ConstructorAccess<?> getActionControllerConstructorAccess() {
if (Objects.isNull(this.actionControllerConstructorAccess)) {
this.actionControllerConstructorAccess = ConstructorAccess.get(this.actionControllerClazz);
}

return actionControllerConstructorAccess;
}

/**
* {@link ActionCommand} 命令的构建器
* <p>
Expand All @@ -168,8 +182,6 @@ static final class Builder {
int subCmd;
/** 方法访问器 */
MethodAccess actionMethodAccess;
/** 类访问器 */
ConstructorAccess<?> actionControllerConstructorAccess;
/** 方法名 */
String actionMethodName;
/** tcp controller类 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ ActionCommandParser buildAction(List<Class<?>> controllerList) {
this.getActionControllerStream(controllerList).forEach(controllerClazz -> {
// 方法访问器: 获取类中自己定义的方法
var methodAccess = MethodAccess.get(controllerClazz);
var constructorAccess = ConstructorAccess.get(controllerClazz);

// 主路由 (类上的路由)
int cmd = controllerClazz.getAnnotation(ActionController.class).value();
Expand Down Expand Up @@ -123,7 +122,6 @@ ActionCommandParser buildAction(List<Class<?>> controllerList) {
.setCmd(cmd)
.setSubCmd(subCmd)
.setActionControllerClazz(controllerClazz)
.setActionControllerConstructorAccess(constructorAccess)
.setActionMethod(method)
.setActionMethodName(methodName)
.setActionMethodIndex(methodIndex)
Expand Down

0 comments on commit e3abc36

Please sign in to comment.