-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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(core): add sugar function for model binding #832
Conversation
c49f51e
to
f7c3886
Compare
@slnode test please |
packages/core/src/application.ts
Outdated
@@ -41,6 +41,12 @@ export class Application extends Context { | |||
this.controller(ctor); | |||
} | |||
} | |||
|
|||
if (options.models) { |
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.
Based on #742, should we remove options.models
support?
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.
ah yes, i wrote this before the discussion. I'll get rid of this option
f7c3886
to
d3aff02
Compare
d3aff02
to
9a4b6d8
Compare
The code changes look reasonably to me, but I am not sure what is the value of these bindings? So far, our Best Practices don't register models for dependency injection because models and repositories are pretty tightly coupled together. How do you envision that this model registry will be used in applications? What will the new best practices look like? What kind of changes will be needed in https://github.com/strongloop/loopback4-example-getting-started? |
@bajtos I'm currently working on #786 which would leverage the
|
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.
I'm currently working on #786 which would leverage the @model and @Property decorators to build JSON schemas from their metadata. My approach was to register these models with dependency injection at boot in order to get their constructors to use as keys to access the metadata.
I am afraid I still don't understand. Could you please point me to the code where demonstrating this approach? Is it necessary to register those models with DI, cannot we use an approach that's closer to our current Best Practices?
On second thought, once #786 is done we could think about changing our Best Practices section to reflect some of the changes made. An example might be to drop type as a key to pass in for @Property, since our metadata is able to find that out itself.
+1 for dropping type from @property
annotations in our Best Practices code examples.
Ok, let's close it then. |
Description
Adding in sugar function for
ctx.bind('model.modelName').toClass(modelCtor).tag('model')
. This is done as a part of #786 and #441. In order for metadata for the models to be accessed, users require access to the names of the models, which in turn can be provided by using these bindings.Checklist