src/vs/workbench/contrib/notebook/common/notebookEditorModelResolverServiceImpl.ts/NotebookModelReferenceCollection/createReferencedObject
class NotebookModelReferenceCollection:	protected async createReferencedObject(key: string, viewType: string): Promise<IResolvedNotebookEditorModel> {
		const uri = URI.parse(key);
		const info = await this._notebookService.withNotebookDataProvider(uri, viewType);

		let result: IResolvedNotebookEditorModel;

		if (info instanceof ComplexNotebookProviderInfo) {
			const model = this._instantiationService.createInstance(ComplexNotebookEditorModel, uri, viewType, info.controller);
			result = await model.load();

		} else if (info instanceof SimpleNotebookProviderInfo) {
			const workingCopyTypeId = NotebookWorkingCopyTypeIdentifier.create(viewType);
			let workingCopyManager = this._workingCopyManagers.get(workingCopyTypeId);
			if (!workingCopyManager) {
				const factory = new NotebookFileWorkingCopyModelFactory(viewType, this._notebookService);
				workingCopyManager = <IFileWorkingCopyManager<NotebookFileWorkingCopyModel, NotebookFileWorkingCopyModel>><any>this._instantiationService.createInstance(
					FileWorkingCopyManager,
					workingCopyTypeId,
					factory,
					factory,
				);
				this._workingCopyManagers.set(workingCopyTypeId, workingCopyManager);
			}
			const model = this._instantiationService.createInstance(SimpleNotebookEditorModel, uri, viewType, workingCopyManager);
			result = await model.load();

		} else {
			throw new Error(`CANNOT open ${key}, no provider found`);
		}

		// Whenever a notebook model is dirty we automatically reference it so that
		// we can ensure that at least one reference exists. That guarantees that
		// a model with unsaved changes is never disposed.
		let onDirtyAutoReference: IReference<any> | undefined;

		this._modelListener.set(result, combinedDisposable(
			result.onDidSave(() => this._onDidSaveNotebook.fire(result.resource)),
			result.onDidChangeDirty(() => {
				const isDirty = result.isDirty();
				this._dirtyStates.set(result.resource, isDirty);

				// isDirty -> add reference
				// !isDirty -> free reference
				if (isDirty && !onDirtyAutoReference) {
					onDirtyAutoReference = this.acquire(key, viewType);
				} else if (onDirtyAutoReference) {
					onDirtyAutoReference.dispose();
					onDirtyAutoReference = undefined;
				}

				this._onDidChangeDirty.fire(result);
			}),
			toDisposable(() => onDirtyAutoReference?.dispose()),
		));
		return result;
	}