I am facing a dilemma with my shared module in AngularJS 1.6.5. This module is designed to be used across multiple applications, each requiring different services within the module to be overridden to cater to their specific needs. These variations are mainly related to request authorization methods for different REST endpoints used by the host applications.
The common approach of defining the shared module first and then creating services with similar names in individual applications seems messy and inefficient. Especially considering that each application already has its own set of similar services under different names.
Do you have any suggestions on how to tackle this challenge effectively?
Just to clarify:
In my shared module, there may be directives with controllers that depend on a service
class MyDirectiveController {
/*@ngInject*/
constructor($element, entity) {
this.$element = $element;
this.entity = entity;
}
$onInit() {
this.entity.get(this.id)
.then((data) => this.dataSet = data);
}
}
Within the shared module, there is a placeholder service:
class Entity {
/*@ngInject*/
constructor($q) {
this.$q = $q;
}
get() {
console.info('You must include your own override service for retrieving entity data');
return this.$q.reject();
}
}
My goal is to somehow replace this dummy service in the shared module with a custom service from the parent application:
entity = MyAppEntityService;