Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

减少依赖注入。 #18

Closed
LYZhelloworld opened this issue Jun 24, 2022 · 1 comment
Closed

减少依赖注入。 #18

LYZhelloworld opened this issue Jun 24, 2022 · 1 comment
Assignees
Labels
wontfix This will not be worked on

Comments

@LYZhelloworld
Copy link
Contributor

LYZhelloworld commented Jun 24, 2022

依赖注入通过反射动态绑定对象,容易出现调用层次不明确、难以追踪组件间关系的问题。尽量手动创建对象。

@LYZhelloworld LYZhelloworld changed the title 减少依赖注入。依赖注入通过反射动态绑定对象,容易出现调用层次不明确、难以追踪组件间关系的问题。尽量手动创建对象。 减少依赖注入。 Jun 24, 2022
@LYZhelloworld LYZhelloworld self-assigned this Jun 24, 2022
@LYZhelloworld
Copy link
Contributor Author

LYZhelloworld commented Jun 24, 2022

当前的依赖关系:
Current Design

@startuml Current Design
skinparam linetype ortho
left to right direction

package "Api" {
    [CopilotOperationController]
    [CopilotUserController]
    [CurrentUserService]
}

package "Application" {
    [Handlers (Operation)]
    [Handlers (User)]
}

package "Infrastructure" {
    [MaaCopilotDbContext]
    [CopilotIdService]
    [IdentityService]
    [MailService]
    [SecretService]
}

package "Resources" {
    [ValidationErrorMessage]
    [ApiErrorMessage]
}

[TokenOption]
[DatabaseOption]
[ApplicationOption]
[JwtOption]
[Configuration]

[HttpContextAccessor]
[FluentEmail]

[CopilotOperationController] --> [Handlers (Operation)]
[CopilotUserController] --> [Handlers (User)]

[Handlers (Operation)] --> [CopilotIdService]
[Handlers (Operation)] --> [CurrentUserService]
[Handlers (Operation)] --> [MaaCopilotDbContext]
[Handlers (Operation)] --> [IdentityService]
[Handlers (Operation)] --> [ValidationErrorMessage]
[Handlers (Operation)] --> [ApiErrorMessage]

[Handlers (User)] --> [MaaCopilotDbContext]
[Handlers (User)] --> [CopilotIdService]
[Handlers (User)] --> [CurrentUserService]
[Handlers (User)] --> [MailService]
[Handlers (User)] --> [SecretService]
[Handlers (User)] --> [TokenOption]
[Handlers (User)] --> [ApiErrorMessage]

[CurrentUserService] --> [Configuration]
[CurrentUserService] --> [HttpContextAccessor]
[IdentityService] --> [MaaCopilotDbContext]
[MailService] --> [FluentEmail]
[MailService] --> [ApplicationOption]
[MailService] --> [CurrentUserService]
[SecretService] --> [JwtOption]

[MaaCopilotDbContext] --> [DatabaseOption]

@enduml

预计重构后的依赖关系(移动了部分组件所在的项目,避免循环引用):
Refactored Design

@startuml Refactored Design
skinparam linetype ortho
left to right direction

package "Api" {
    [CopilotOperationController]
    [CopilotUserController]
}

package "Application" {
    [Handlers (Operation)]
    [Handlers (User)]
    [CurrentUserService]
    [CopilotIdService]
    [IdentityService]
    [MailService]
    [SecretService]
}

package "Infrastructure" {
    [MaaCopilotDbContext]
}

package "Resources" {
    [ValidationErrorMessage]
    [ApiErrorMessage]
}

package "Options" {
    [Configuration]
    [TokenOption]
    [DatabaseOption]
    [ApplicationOption]
    [JwtOption]
}

[HttpContextAccessor]
[FluentEmail]

[CopilotOperationController] --> [Handlers (Operation)]
[CopilotUserController] --> [Handlers (User)]

[Handlers (Operation)] --> [CopilotIdService]
[Handlers (Operation)] --> [CurrentUserService]
[Handlers (Operation)] --> [MaaCopilotDbContext]
[Handlers (Operation)] --> [IdentityService]
[Handlers (Operation)] --> [ValidationErrorMessage]
[Handlers (Operation)] --> [ApiErrorMessage]

[Handlers (User)] --> [MaaCopilotDbContext]
[Handlers (User)] --> [CopilotIdService]
[Handlers (User)] --> [CurrentUserService]
[Handlers (User)] --> [MailService]
[Handlers (User)] --> [SecretService]
[Handlers (User)] --> [TokenOption]
[Handlers (User)] --> [ApiErrorMessage]

[CurrentUserService] --> [Configuration]
[CurrentUserService] --> [HttpContextAccessor]
[IdentityService] --> [MaaCopilotDbContext]
[MailService] --> [FluentEmail]
[MailService] --> [ApplicationOption]
[MailService] --> [CurrentUserService]
[SecretService] --> [JwtOption]

[MaaCopilotDbContext] --> [DatabaseOption]

@enduml

@AlisaAkiron AlisaAkiron added the wontfix This will not be worked on label Jun 24, 2022
@AlisaAkiron AlisaAkiron closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants