-
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.
🌿 refactor: lazy load services instead of instantiate them direclty i…
…n addFactory
- Loading branch information
Victor MENDELE
committed
May 21, 2020
1 parent
0a59298
commit 53a03e8
Showing
5 changed files
with
87 additions
and
14 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
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
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,9 +1,33 @@ | ||
import {createServiceContainer} from '../src' | ||
import 'reflect-metadata' | ||
import {createServiceContainer, Inject} from '../src' | ||
import {createPlainServiceLoader} from '../src/factories/createPlainServiceLoader' | ||
import {createReflectServiceLoader} from '../src/factories/createReflectServiceLoader' | ||
import {Service} from '../src/decorators/Service' | ||
|
||
it('should work', function () { | ||
const container = createServiceContainer({ | ||
useReflection: false, | ||
serviceLoader: createPlainServiceLoader([], []) | ||
}) | ||
}) | ||
|
||
it('should work 2', function () { | ||
|
||
@Service('myService') | ||
class MyService { | ||
constructor( | ||
@Inject('myFactory') hello: string | ||
) { | ||
console.log(hello) | ||
} | ||
} | ||
|
||
const loader = createReflectServiceLoader([ MyService ], []) | ||
|
||
const container = createServiceContainer({ | ||
useReflection: true, | ||
serviceLoader: loader | ||
}) | ||
|
||
container.addFactory('myFactory', () => 'hello world') | ||
}) |