How do you inject a factory function with an Aurelia DI container?

I would like to make a third party injection object window

so that I can test functionality independently of the third party service. The component I'm trying to create is a simple wrapper around Disqus inline comments. factory I would like to use as simple as

() => window.DISQUS

      

Anyone could do this or know if this is possible?

+3


source to share


1 answer


Use registerInstance

with a string key like this:

container.registerInstance('disqus', window.DISQUS);

      



Then you can inject an instance of disqus into your view models like this:

import {inject} from 'aurelia-framework';

@inject('disqus')
export class Foo {
  constructor(disqus) {
    this.disqus = disqus;
  }
  ...
}

      

+4


source







All Articles