How to use the @aurelia/kernel.DI.createContainer function in @aurelia/kernel

To help you get started, we’ve selected a few @aurelia/kernel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aurelia / aurelia / packages / __tests__ / 3-runtime-html / self-binding-behavior.spec.ts View on Github external
describe('SelfBindingBehavior', function () {
  const container: IContainer = DI.createContainer();
  let sut: SelfBindingBehavior;
  let binding: PropertyBinding;
  let originalCallSource: () => void;

  // eslint-disable-next-line mocha/no-hooks
  beforeEach(function () {
    sut = new SelfBindingBehavior();
    binding = new PropertyBinding(undefined, undefined, undefined, undefined, undefined, container as any);
    originalCallSource = binding['callSource'] = function () { return; };
    binding['targetEvent'] = 'foo';
    sut.bind(undefined, undefined, binding as any);
  });

  // TODO: test properly (different binding types)
  it('bind()   should apply the correct behavior', function () {
    assert.strictEqual(binding['selfEventCallSource'] === originalCallSource, true, `binding['selfEventCallSource'] === originalCallSource`);
github aurelia / aurelia / packages / __tests__ / kernel / di.integration.spec.ts View on Github external
it(`enables the handler class to provide registrations for data`, () => {
    const container = DI.createContainer();
    const data = {};

    container.register(
      Registration.singleton('.css', FakeCSSHandler)
    );

    container.register(
      Registration.defer('.css', data)
    );

    const service = container.get(FakeCSSService);

    assert.strictEqual(service.data, data);
  });
github aurelia / aurelia / packages / __tests__ / 3-runtime-html / styles.spec.ts View on Github external
it('components do not inherit parent component styles', function () {
      const rootContainer = DI.createContainer();
      const parentContainer = rootContainer.createChild();

      const registry = new CSSModulesProcessorRegistry();
      registry.register(parentContainer, {});

      const childContainer = parentContainer.createChild();

      const parentResources = new RuntimeCompilationResources(parentContainer);
      const childResources = new RuntimeCompilationResources(childContainer);

      const fromParent = parentResources.find(CustomAttribute, 'class');
      const fromChild = childResources.find(CustomAttribute, 'class');

      assert.equal(fromParent.name, 'class');
      assert.equal(fromChild, null);
    });
github aurelia / aurelia / packages / __tests__ / 1-kernel / di.spec.ts View on Github external
it(`inherits non-resource obj keyed factories from root`, function () {
      const type = class {};
      const key = {} as any;

      const parent = DI.createContainer();

      parent.register(Registration.singleton(key, type));

      const factoryFromParent = parent.getFactory(key);

      const child = parent.createChild();

      const factoryFromChild = child.getFactory(key);

      assert.strictEqual(factoryFromParent, factoryFromChild);
    });
github aurelia / aurelia / packages / __tests__ / 4-jit / attribute-pattern.spec.ts View on Github external
it(`parse [${defs.map(d => d.pattern)}] -> interpret [${value}] -> match=[${match}]`, function () {
          let receivedRawName: string;
          let receivedRawValue: string;
          let receivedParts: string[];
          @attributePattern(...defs)
          class ThePattern {}
          for (const { pattern } of defs) {
            ThePattern.prototype[pattern] = (rawName, rawValue, parts) => {
              receivedRawName = rawName;
              receivedRawValue = rawValue;
              receivedParts = parts;
            };
          }
          const container = DI.createContainer();
          container.register(ThePattern as any);
          const interpreter = container.get(ISyntaxInterpreter);
          const attrPattern = container.get(IAttributePattern);
          interpreter.add(attrPattern.$patternDefs);

          const result = interpreter.interpret(value);
          if (match != null) {
            assert.strictEqual(
              attrPattern.$patternDefs.map(d => d.pattern).includes(result.pattern),
              true,
              `attrPattern.$patternDefs.map(d => d.pattern).indexOf(result.pattern) >= 0`
            );
            attrPattern[result.pattern](value, 'foo', result.parts);
            assert.strictEqual(receivedRawName, value, `receivedRawName`);
            assert.strictEqual(receivedRawValue, 'foo', `receivedRawValue`);
            assert.deepStrictEqual(receivedParts, result.parts, `receivedParts`);
github aurelia / aurelia / packages / __tests__ / util.ts View on Github external
export function createObserverLocator(containerOrLifecycle?: IContainer | ILifecycle): IObserverLocator {
  let container: IContainer;
  if (containerOrLifecycle === undefined || !('get' in containerOrLifecycle)) {
    container = DI.createContainer();
    container.register(ILifecycleRegistration);
  } else {
    container = containerOrLifecycle as IContainer;
  }
  const lifecycle = container.get(ILifecycle);
  const dummyLocator: any = {
    handles(): boolean {
      return false;
    }
  };
  Registration.instance(IDirtyChecker, null).register(container);
  Registration.instance(ITargetObserverLocator, dummyLocator).register(container);
  Registration.instance(ITargetAccessorLocator, dummyLocator).register(container);
  container.register(IObserverLocatorRegistration);
  return container.get(IObserverLocator);
}
github aurelia / aurelia / packages / __tests__ / runtime / value-converter.spec.ts View on Github external
beforeEach(function () {
    container = DI.createContainer();
  });
github aurelia / aurelia / packages / testing / dist / esnext / test-builder.js View on Github external
export function createObserverLocator(containerOrLifecycle) {
    let container;
    if (containerOrLifecycle === undefined || !('get' in containerOrLifecycle)) {
        container = DI.createContainer();
        container.register(ILifecycleRegistration);
    }
    else {
        container = containerOrLifecycle;
    }
    const dummyLocator = {
        handles() {
            return false;
        }
    };
    Registration.instance(IDirtyChecker, null).register(container);
    Registration.instance(ITargetObserverLocator, dummyLocator).register(container);
    Registration.instance(ITargetAccessorLocator, dummyLocator).register(container);
    container.register(IObserverLocatorRegistration);
    return container.get(IObserverLocator);
}
github aurelia / aurelia / packages / runtime-html-browser / dist / esnext / index.js View on Github external
createContainer() {
        return this.register(DI.createContainer());
    }
};
github aurelia / aurelia / packages / runtime / src / aurelia.ts View on Github external
  constructor(container: IContainer = DI.createContainer()) {
    this.container = container;
    this.task = LifecycleTask.done;

    this._isRunning = false;
    this._isStarting = false;
    this._isStopping = false;

    this._root = void 0;

    this.next = (void 0)!;

    Registration.instance(Aurelia, this).register(container);
  }