ManagedDataModel.fromCurrentMirrorSystem constructor Null safety

ManagedDataModel.fromCurrentMirrorSystem()

Creates an instance of a ManagedDataModel from all subclasses of ManagedObject in all libraries visible to the calling library.

This constructor will search every available package and file library that is visible to the library that runs this constructor for subclasses of ManagedObject. A ManagedEntity will be created and stored in this instance for every such class found.

Standard Dart libraries (prefixed with 'dart:') and URL-encoded libraries (prefixed with 'data:') are not searched.

This is the preferred method of instantiating this type.

Implementation

ManagedDataModel.fromCurrentMirrorSystem() {
  final runtimes = RuntimeContext.current.runtimes.iterable
      .whereType<ManagedEntityRuntime>();

  for (final runtime in runtimes) {
    _entities[runtime.entity.instanceType] = runtime.entity;
    _tableDefinitionToEntityMap[runtime.entity.tableDefinition] =
        runtime.entity;
  }
  for (final runtime in runtimes) {
    runtime.finalize(this);
  }
}