sourcefuse / loopback4-starter

Loopback 4 starter application. Multi-tenant architecture supported. Authentication, Authorization, Soft deletes, environment vars, Audit logs, included.
MIT License
158 stars 59 forks source link

[Question] How to define belongs to user relationship when creating a component? #47

Closed pbalan closed 3 years ago

pbalan commented 4 years ago

Hi,

I'd like to develop my application logic as components and use this as the base application.

I'm not clear about how I can inject the user into the component especially when using a user-modifiable entity as the abstract class.

Could you please provide me a direction on it?

samarpan-b commented 4 years ago

You can get all injectables from application instance from within your component.

@inject(CoreBindings.APPLICATION_INSTANCE) private readonly application: RestApplication,

For example, here I am trying to get a datasource from the application instance

const redisDS = (await this.application.get(
        `datasources.${this.config.name}`,
      )) as juggler.DataSource;

I think this can help you get any of the bindings including user component. Hope this helps.

samarpan-b commented 4 years ago

@pbalan can I close this issue now ?