-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inversify-code-examples): add isBound examples
- Loading branch information
1 parent
db161bb
commit 3b92b7a
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/docs/tools/inversify-code-examples/src/examples/containerApiIsBound.spec.ts
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,17 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
|
||
import { | ||
isKatanaBound, | ||
isKatanaSymbolBound, | ||
isNinjaBound, | ||
isWarriorSymbolBound, | ||
} from './containerApiIsBound'; | ||
|
||
describe('Container API (isBound)', () => { | ||
it('should detect bound and not bound services', async () => { | ||
expect(isKatanaBound).toBe(false); | ||
expect(isKatanaSymbolBound).toBe(false); | ||
expect(isNinjaBound).toBe(true); | ||
expect(isWarriorSymbolBound).toBe(true); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/docs/tools/inversify-code-examples/src/examples/containerApiIsBound.ts
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,39 @@ | ||
import { Container, injectable } from 'inversify'; | ||
|
||
// Begin-example | ||
interface Warrior { | ||
kind: string; | ||
} | ||
|
||
const katanaSymbol: symbol = Symbol.for('Katana'); | ||
const warriorSymbol: symbol = Symbol.for('Warrior'); | ||
|
||
@injectable() | ||
class Ninja implements Warrior { | ||
public readonly kind: string = 'ninja'; | ||
} | ||
|
||
@injectable() | ||
class Katana {} | ||
|
||
const container: Container = new Container(); | ||
container.bind<Warrior>(Ninja).to(Ninja); | ||
container.bind<Warrior>(warriorSymbol).to(Ninja); | ||
|
||
// returns true | ||
const isNinjaBound: boolean = container.isBound(Ninja); | ||
// returns true | ||
const isWarriorSymbolBound: boolean = container.isBound(warriorSymbol); | ||
// returns false | ||
const isKatanaBound: boolean = container.isBound(Katana); | ||
// returns false | ||
const isKatanaSymbolBound: boolean = container.isBound(katanaSymbol); | ||
|
||
// End-example | ||
|
||
export { | ||
isKatanaBound, | ||
isKatanaSymbolBound, | ||
isNinjaBound, | ||
isWarriorSymbolBound, | ||
}; |