3

I'd like to make a third-party object on the window injectable so that I can test functionality independent of the third-party service. The component I'm trying to build is a simple wrapper around Disqus embedded comments. The factory I would like to use is as simple as

() => window.DISQUS

Has anyone been able to do this or know if it is possible?

lukewestby
  • 1,207
  • 8
  • 15

1 Answers1

4

Use registerInstance with a string key like this:

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

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

import {inject} from 'aurelia-framework';

@inject('disqus')
export class Foo {
  constructor(disqus) {
    this.disqus = disqus;
  }
  ...
}
Jeremy Danyow
  • 26,470
  • 12
  • 87
  • 133