-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(container): add self registration of container in constructor, t… #101
feat(container): add self registration of container in constructor, t… #101
Conversation
…est, and document it
Thank your for the PR, I'll take a look tomorrow. You can try implementing this one , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I like this. Please make some changes (where I commented) and I'll merge this.
Keep in mind that master branch is already several commits ahead. If you have any question let's discuss here.
src/lib/container.interface.ts
Outdated
@@ -6,6 +6,8 @@ export interface IContainerOptions { | |||
} | |||
|
|||
export interface IContainer { | |||
[key: string]: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing that it's a bad practise. Interface (aka super type) should define only public methods. Unless you use interface for defining structure of value objects. Please remove that.
src/lib/container.ts
Outdated
@@ -21,6 +21,7 @@ export class Container implements IContainer { | |||
this.parent = <IContainer> options.parent; | |||
this.defaultLifeTime = options.defaultLifeTime || this.defaultLifeTime; | |||
} | |||
this.register({ token: TContainer, useValue: this }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did right! But I'm gonna release that simplified Reflect API which is gonna allow us to inject stuff by just specifying it's type like this constructor (private container: Container) {}
. Please use Container as the token in this case.
src/tests/container.spec.ts
Outdated
it('should register itself for injection', () => { | ||
// arrange, act | ||
const actual = container.resolve(TContainer); | ||
// assert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't deny that comments like this one are obvious. Clearly named variables and methods won't need any comments above them. Please remove them.
@Tolowe Tt's better to just close this PR, then pull changes and then fix yours and open new PR. |
@ThoHoh I think I have everything fixed as you mentioned. |
@Tolowe Thank you! |
…est, and document it