-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: impl MultiInstance inject MultiInstance (#240)
<!-- Thank you for your pull request. Please review below requirements. Bug fixes and new features should include tests and possibly benchmarks. Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md 感谢您贡献代码。请确认下列 checklist 的完成情况。 Bug 修复和新功能必须包含测试,必要时请附上性能测试。 Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md --> ##### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] `npm test` passes - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added - [ ] commit message follows commit guidelines ##### Affected core subsystem(s) <!-- Provide affected core subsystem(s). --> ##### Description of change <!-- Provide a description of the change below this comment. --> <!-- - any feature? - close https://github.com/eggjs/egg/ISSUE_URL --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced support for multi-instance prototypes, enhancing the module's capability to manage multiple instances of classes. - Added new classes (`MultiInstanceProtoNode`, `BizManager`, `Secret`, `App`, `App2`) to facilitate dependency injection and configuration management. - Implemented new methods for handling multi-instance logic and retrieving class instances. - **Bug Fixes** - Improved lifecycle management for multi-instance hooks. - **Tests** - Added comprehensive test cases to validate the functionality of multi-instance injection and module management. - **Documentation** - Updated configuration files and module structures to reflect the new multi-instance capabilities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
36 changed files
with
721 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import { PrototypeUtil } from '@eggjs/core-decorator'; | ||
import type { EggProtoImplClass, LifecycleHook, LoadUnit, LoadUnitLifecycleContext } from '@eggjs/tegg-types'; | ||
import { EggPrototypeCreatorFactory } from '../factory/EggPrototypeCreatorFactory'; | ||
import { EggPrototypeFactory } from '../factory/EggPrototypeFactory'; | ||
// import { EggPrototypeCreatorFactory } from '../factory/EggPrototypeCreatorFactory'; | ||
// import { EggPrototypeFactory } from '../factory/EggPrototypeFactory'; | ||
|
||
export class LoadUnitMultiInstanceProtoHook implements LifecycleHook<LoadUnitLifecycleContext, LoadUnit> { | ||
multiInstanceClazzSet: Set<EggProtoImplClass> = new Set(); | ||
static multiInstanceClazzSet: Set<EggProtoImplClass> = new Set(); | ||
|
||
async preCreate(ctx: LoadUnitLifecycleContext, loadUnit: LoadUnit): Promise<void> { | ||
const clazzList = ctx.loader.load(); | ||
const multiInstanceClazzList = Array.from(this.multiInstanceClazzSet); | ||
static setAllClassList(clazzList: readonly EggProtoImplClass[]) { | ||
for (const clazz of clazzList) { | ||
if (PrototypeUtil.isEggMultiInstancePrototype(clazz)) { | ||
this.multiInstanceClazzSet.add(clazz); | ||
} | ||
} | ||
for (const clazz of multiInstanceClazzList) { | ||
const protos = await EggPrototypeCreatorFactory.createProto(clazz, loadUnit); | ||
for (const proto of protos) { | ||
EggPrototypeFactory.instance.registerPrototype(proto, loadUnit); | ||
} | ||
} | ||
} | ||
|
||
static clear() { | ||
this.multiInstanceClazzSet.clear(); | ||
} | ||
|
||
async preCreate(): Promise<void> { | ||
// ... | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.