How to use the @aurelia/kernel.Registration.instance 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 / runtime-html / dist / esnext / styles / style-configuration.js View on Github external
if (localStyles.find(x => typeof x !== 'string')) {
                        // TODO: use reporter
                        throw new Error('Shadow DOM CSS must be a string.');
                    }
                    return new StyleElementStyles(dom, localStyles, sharedStyles);
                };
            }
            let globalStyles;
            if (config && config.sharedStyles) {
                globalStyles = createStyles(config.sharedStyles, null);
            }
            else {
                globalStyles = noopShadowDOMStyles;
            }
            container.register(Registration.instance(IShadowDOMGlobalStyles, globalStyles));
            container.register(Registration.instance(ext, new ShadowDOMRegistry(globalStyles, createStyles)));
        });
    }
github aurelia / aurelia / packages / runtime / dist / esnext / render-context.js View on Github external
container.registerResolver(IController, renderableProvider);
        container.registerResolver(ITargetedInstruction, instructionProvider);
        container.registerResolver(IRenderLocation, renderLocationProvider);
        if (dependencies != void 0) {
            container.register(...dependencies);
        }
        // If the element has a view, support Recursive Components by adding self to own view template container.
        if (componentType) {
            const def = CustomElement.getDefinition(componentType);
            def.register(container);
            if (componentInstance !== void 0) {
                const injectable = def.injectable;
                if (injectable !== null) {
                    // If the element is registered as injectable, support injecting the instance into children
                    // Note: this provider is never disposed at the moment. Perhaps we need to at some point, but not disposing it here doesn't necessarily need to cause memory leaks. Keep an eye on it though.
                    Registration.instance(injectable, componentInstance).register(container);
                }
            }
        }
    }
    get id() {
github aurelia / aurelia / packages / testing / src / test-builder.ts View on Github external
container = DI.createContainer();
    container.register(ILifecycleRegistration);
  } else {
    container = containerOrLifecycle;
  }
  const dummyLocator: any = {
    handles(): boolean {
      return false;
    }
  };
  const dummyScheduler: any = {

  };
  Registration.instance(IDirtyChecker, null).register(container);
  Registration.instance(ITargetObserverLocator, dummyLocator).register(container);
  Registration.instance(ITargetAccessorLocator, dummyLocator).register(container);
  container.register(IObserverLocatorRegistration);
  Registration.instance(IScheduler, dummyScheduler).register(container);
  return container.get(IObserverLocator);
}
github aurelia / aurelia / packages / __tests__ / 2-runtime / computed-observer.spec.ts View on Github external
function createFixture() {
    const container = RuntimeConfiguration.createContainer();
    const innerLocator = {
      handles() { return false; }
    };
    Registration.instance(ITargetAccessorLocator, innerLocator).register(container);
    Registration.instance(ITargetObserverLocator, innerLocator).register(container);
    const locator = container.get(IObserverLocator);
    const dirtyChecker = container.get(IDirtyChecker);
    const lifecycle = container.get(ILifecycle);
    const scheduler = container.get(IScheduler);

    return { container, locator, dirtyChecker, lifecycle, scheduler };
  }
github aurelia / aurelia / packages / __tests__ / setup-test262.ts View on Github external
public constructor() {
    const container = this.container = DI.createContainer();
    container.register(
      Registration.instance(ILogConfig, new LogConfig(ColorOptions.noColors, LogLevel.info)),
      Registration.instance(ISink, new BufferedFileSink()),
      Registration.instance(ISink, new ConsoleSink(console)),
      Registration.singleton(IFileSystem, NodeFileSystem),
    );
    this.fs = container.get(IFileSystem);
    this.logger = container.get(ILogger).scopeTo('TestRunner');
  }
github aurelia / aurelia / packages / testing / src / template-controller-tests.ts View on Github external
const lifecycle = container.get(ILifecycle);

  let location: IRenderLocation & AuNode = null!;

  container.register(AttributeType);

  if (AttributeType.description.isTemplateController) {
    const loc = AuNode.createRenderLocation();
    AuNode.createHost().appendChild(loc.$start!).appendChild(loc);
    const createView: (factory: FakeViewFactory) => IController = factory => {
      const view = new FakeView(lifecycle, factory);
      view.$nodes = new AuNodeSequence(new AuDOM(), AuNode.createTemplate().appendChild(AuNode.createText()));
      return view;
    };
    container.register(
      Registration.instance(
        IRenderLocation,
        location = ((options.target as typeof loc) || loc) as any
      ),
      Registration.instance(IViewFactory, new FakeViewFactory('fake-view', createView, lifecycle))
    );
  } else {
    const hostProvider = new InstanceProvider();
    hostProvider.prepare(options.target || AuNode.createHost());

    dom.registerElementResolver(container, hostProvider);
  }

  const attribute = container.get & IViewModel>(
    CustomAttributeResource.keyFrom(AttributeType.description.name)
  );
  attribute.$hydrate(LF.none, container);
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 / runtime / dist / esnext / aurelia.js View on Github external
constructor(container = 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);
    }
    get isRunning() {
github aurelia / aurelia / packages / aot / src / service-host.ts View on Github external
public executeEntryFile(dir: string): Promise<$Any> {
    const container = this.container.createChild();
    container.register(Registration.instance(ISourceFileProvider, new EntrySourceFileProvider(this, dir)));

    return this.agent.RunJobs(container);
  }
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);
  }