How do you inject the services you need into an extension data loader

cancel
Showing results for 
Search instead for 
Did you mean: 
boneill
Partner

How do you inject the services you need into an extension data loader

I have set up a data loader in my extension and configured it to load successfully from the aca app.

However, it is pretty useless as I cannot figure out how to inject a service into the data loader function.

My code follows the aca documentation https://alfresco-content-app.netlify.app/#/extending/custom-extension-loaders.  This shows you well how to set up a loader but skips over how to add a service to the ExtensionLoaderCallback.  The frustrating thing is that the example actually shows the callback using a service.  However, because the callback is implemented as a constant function I cannot figure out how to inject or use a service within it as it has no constructor for DI.

I have tried this (note I inject a service using inject) but it fails when the loader runs as the loader guard does not recognise it as the expected function template and the service does not get loaded:

 export const myExtensionLoader = new InjectionToken('Extension Configuration', {
    factory: () => (route: ActivatedRouteSnapshot) => {
 
      return inject(MyConfigurationService).loadConfig();
   }
 });
I cannot find any other way of injecting the services I need into an exported constant.
 
The following runs fine but as you can see has no service injected.
 
export const myExtensionLoader = (route: ActivatedRouteSnapshot) => {
  console.log("My EXTENSION for route", route);
  return of(true);
}
 
Hoping someone as tried to use a loader.  I cannot find any examples online and the included libraries for the aca app dont seem to use it.  Seems like the right way to do things though.
 
Thanks for any help
 
Brian