-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add decorator for asynchronous injection and optimize previous …
…module registry
- Loading branch information
Showing
15 changed files
with
271 additions
and
208 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './interface'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Inject } from '@nestjs/common'; | ||
|
||
import { StaticStore } from '../structs'; | ||
import { getToken } from '../method'; | ||
import { AsyncProviderFactory, Class } from '../common'; | ||
|
||
/** | ||
* Use this decorator to handle dependency management for asynchronous provider factory classes. | ||
* | ||
* @param target The asynchronous provider factory class. | ||
* | ||
* @publicApi | ||
*/ | ||
export function AsyncInjectable(target: Class<AsyncProviderFactory>) { | ||
StaticStore.set(target.name); | ||
} | ||
/** | ||
* Use this decorator to inject the asynchronous provider into the class instantiation process. | ||
* | ||
* @param target The asynchronous provider factory class. | ||
* | ||
* @publicApi | ||
*/ | ||
export function AsyncInject(target: Class<AsyncProviderFactory>) { | ||
const token = getToken(target); | ||
return Inject(token); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './async-inject'; | ||
export * from './module'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './base'; | ||
export * from './common'; | ||
export * from './decorator'; | ||
export * from './method'; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { AsyncProviderFactory, Class } from '../common'; | ||
import { StaticStore } from '../structs'; | ||
|
||
/** | ||
* The corresponding injected token value is obtained by passing in the asynchronous provider factory class. | ||
* | ||
* @param target The asynchronous provider factory class. | ||
* @returns token (symbol) | ||
* | ||
* @publicApi | ||
*/ | ||
export function getToken(target: Class<AsyncProviderFactory>) { | ||
const token = StaticStore.get(target.name); | ||
return token; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './async-inject'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './store'; |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class StaticStore { | ||
private static readonly map = new Map<string, symbol>(); | ||
|
||
public static get(key: string) { | ||
return StaticStore.map.get(key); | ||
} | ||
|
||
public static set(key: string) { | ||
StaticStore.map.set(key, Symbol(key)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.