Skip to content
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

Extract registration name from function and class #26

Closed
mikhasd opened this issue Jul 11, 2017 · 3 comments
Closed

Extract registration name from function and class #26

mikhasd opened this issue Jul 11, 2017 · 3 comments
Assignees

Comments

@mikhasd
Copy link

mikhasd commented Jul 11, 2017

It would prevent typing the names twice in several occasions:

class MyClass { /* ... */}
function myFunction(MyClass){ /* ... */ }

// AS IS
container.registerClass('MyClass', MyClass);
container.registerFunction('myFunction', myFunction);

// SUGGESTION
container.registerClass(MyClass);
container.registerFunction(myFunction);

container.register(MyClass);
container.register(myFunction);
@jeffijoe
Copy link
Owner

I like the suggestion, but in case .name does not actually return what you expect, you wouldn't know what it was registered as. For example:

const myFunction = function myAwesomeFunction () {}

container.registerFunction(myFunction)

container.resolve('myFunction') // boom

Additionally, it can only work for registerClass and registerFunction, not register (because you don't register actual values with register, you use the asClass/asFunction chains)

Thoughts?

@mikhasd
Copy link
Author

mikhasd commented Jul 11, 2017

Agreed: this behavior could be applied only on registerClass and registerFunction.

@jeffijoe jeffijoe self-assigned this Jul 12, 2017
jeffijoe added a commit that referenced this issue Jul 12, 2017
@jeffijoe
Copy link
Owner

Implemented and released as 2.6.0. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants