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
Register single dependency #120
Comments
Suggestion, add helper to convert to expected type: const simple = (obj = {}) => deps => Object
.entries(obj)
.reduce((result, [key, fn]) => ({ ...result, [key]: fn(deps) }), {});
const constants = (obj = {}) => () => Object
.entries(obj)
.reduce((result, [key, value]) => ({ ...result, [key]: value }), {}); usage: laconia(app)
.register(simple({
orderStream: ({env}) => myOwnFactory(env.ORDER_STREAM_NAME)
}))
.register(constants({
ONE: 1,
foo: 'bar'
})); |
That's an interesting pattern! I guess if I want to register a single dependency, we can do it like this? laconia(app)
.register(single("orderStream", ({env}) => myOwnFactory(env.ORDER_STREAM_NAME))) What are the pro and cons between the two approaches? |
|
Thanks @hugosenari! It looks like the pro and cons can be derived into:
From the framework point of view, I think we should prefer user experience. On the other hand, I don't think they're mutually exclusive, if there are enough common adapter patterns in the user land, we should try to absorb it into the framework. That said, would you be interested to make a PR for this feature? |
…(name, factory, options)`
The pull request that add I'm not sure about naming, but is better than my other approach that tried to overload register. ;-) |
@hugosenari I didn't realize how difficult it is to overload things in JavaScript, my bad. Maybe adding a new method is a good way to go, I'll continue the conversation in the PR. |
…onia/packages/laconia-core/test/types/index.ts`
Is your feature request related to a problem? Please describe.
When I need to register a single dependency, the current Laconia API is asking me to return an object, which lead to a verbose code.
Describe the solution you'd like
This will also allow users to decouple their factories better from Laconia:
The text was updated successfully, but these errors were encountered: