-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inversify-site): update next getting started API docs
- Loading branch information
1 parent
430c4bf
commit f661358
Showing
3 changed files
with
38 additions
and
2 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
9 changes: 9 additions & 0 deletions
9
packages/docs/tools/inversify-code-examples/src/examples/v7/gettingStarted.int.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,9 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
|
||
import { ninja } from './gettingStarted'; | ||
|
||
describe('getting started', () => { | ||
it('should provide a ninja with a weapon with right damage', () => { | ||
expect(ninja.katana.damage).toBe(10); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
packages/docs/tools/inversify-code-examples/src/examples/v7/gettingStarted.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,27 @@ | ||
// Is-inversify-import-example | ||
import { Container, inject, injectable } from 'inversify7'; | ||
|
||
@injectable() | ||
class Katana { | ||
public readonly damage: number = 10; | ||
} | ||
|
||
@injectable() | ||
class Ninja { | ||
constructor( | ||
@inject(Katana) | ||
public readonly katana: Katana, | ||
) {} | ||
} | ||
|
||
const container: Container = new Container(); | ||
|
||
container.bind(Ninja).toSelf(); | ||
container.bind(Katana).toSelf(); | ||
|
||
const ninja: Ninja = container.get(Ninja); | ||
|
||
console.log(ninja.katana.damage); // Prints 10 | ||
// End-example | ||
|
||
export { ninja }; |