Reputation: 973
I am creating multiple Ember engines (which are like mini-apps) that lie within parent app. Each engine can define its own services/controllers/routes. But when you go to the landing page of an engine, for eg., there might be an exact same API call that each engine makes.
This API call might be defined in a service hosting this call, residing in the engine. some-service.js
import ...
export default Service.extend({
store: service(),
getlandingPageInfo(query) {
validateQuery(query);
return this.get('store')
.queryRecord(some-model, query);
},
});
Now my other engine's landing page also needs the same call. But for this, I will have to copy all of some-model
some-service
, some-adapter
and some-serializer
into that engine. How can I re-use the methods in one service in some other service DRY?
Ember doesn't allow services to be imported between engines.
Upvotes: 1
Views: 572
Reputation: 594
You can define your engine's engine.js
which services to make available from your host app in your engine. See http://ember-engines.com/guide/services
Engine.js
const Eng = Engine.extend({
modulePrefix,
Resolver,
dependencies: {
services: [
'store',
'session',
'ajax',
'router'
],
externalRoutes: ['dashboard']
}
});
However, if you have ServiceX
in Engine B, and want to share that service with Engine A, you'd need to create a separate addon (likely an in-repo addon in the host app) to share those services accross
Upvotes: 1