Skip to content

Conversation

@raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented May 9, 2020

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@raymondfeng raymondfeng changed the title Bind models feat(cli): bind model classes during boot May 9, 2020
@raymondfeng raymondfeng self-assigned this May 9, 2020
Copy link
Member

@achrinza achrinza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

This is useful for context inspection to know what model classes are in
an application.
@pookdeveloper
Copy link

I need it in my project that I use, please review it as soon as you can thanks! :)

Copy link
Contributor

@hacksparrow hacksparrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from that debug message, it LGTM.

@raymondfeng raymondfeng merged commit 2de7d5f into master May 13, 2020
@raymondfeng raymondfeng deleted the bind-models branch May 13, 2020 15:09

debug('Bind class: %s', cls.name);
// We are binding the model class itself
const binding = this.app.bind(`models.${cls.name}`).to(cls).tag('model');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raymondfeng can you please extract the code building the binding to a standalone function that can be used to bind models manually, in cases where @loopback/boot is not involved? For example in extensions.

const binding = createModelClassBinding(cls);
app.add(binding);

Similar helpers we already have: createComponentApplicationBooterBinding, createBindingFromClass, createBodyParserBinding, createServiceBinding.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants