From ddc2473f984fdafbfd58ae90fae36bc0c1ca7412 Mon Sep 17 00:00:00 2001
From: 1ncounter <1ncounter.100@gmail.com>
Date: Thu, 1 Aug 2024 10:01:57 +0800
Subject: [PATCH] refactor: adjust dicts

---
 .../src/runtime/createComponent.tsx           |   1 -
 .../react-renderer/src/runtime/elements.tsx   |   3 +-
 .../code-runtime/codeRuntime.ts               |   6 +-
 .../code-runtime/codeRuntimeService.ts        |   6 +-
 .../{services => }/code-runtime/codeScope.ts  |   2 +-
 .../{services => }/code-runtime/evaluate.ts   |   0
 .../code-runtime/globals-es2015.ts            |   0
 .../src/{services => }/code-runtime/index.ts  |   0
 .../src/{services => }/code-runtime/value.ts  |   0
 packages/renderer-core/src/createRenderer.ts  | 109 +++++++++++-------
 .../src/{services => }/extension/boosts.ts    |   4 +-
 .../extension/extensionHostService.ts         |  20 ++--
 .../src/{services => }/extension/index.ts     |   0
 .../src/{services => }/extension/plugin.ts    |   2 +-
 .../src/{services => }/extension/render.ts    |   0
 packages/renderer-core/src/index.ts           |  31 +++--
 packages/renderer-core/src/intl/index.ts      |   1 +
 .../intlService.ts}                           |   4 +-
 .../renderer-core/src/life-cycle/index.ts     |   1 +
 .../lifeCycleService.ts                       |   0
 .../model/componentTreeModel.ts               |   8 +-
 .../model/componentTreeModelService.ts        |   2 +-
 .../src/{services => }/model/index.ts         |   0
 .../src/{services => }/package/index.ts       |   0
 .../package/managementService.ts              |   2 +-
 .../src/{services => }/package/package.ts     |   0
 .../src/{services => }/schema/index.ts        |   0
 .../{services => }/schema/schemaService.ts    |   2 +-
 .../src/{services => }/schema/validation.ts   |   0
 packages/renderer-core/src/types.ts           |  32 -----
 packages/renderer-core/src/util/index.ts      |   1 +
 .../utilService.ts}                           |   4 +-
 32 files changed, 118 insertions(+), 123 deletions(-)
 rename packages/renderer-core/src/{services => }/code-runtime/codeRuntime.ts (97%)
 rename packages/renderer-core/src/{services => }/code-runtime/codeRuntimeService.ts (91%)
 rename packages/renderer-core/src/{services => }/code-runtime/codeScope.ts (97%)
 rename packages/renderer-core/src/{services => }/code-runtime/evaluate.ts (100%)
 rename packages/renderer-core/src/{services => }/code-runtime/globals-es2015.ts (100%)
 rename packages/renderer-core/src/{services => }/code-runtime/index.ts (100%)
 rename packages/renderer-core/src/{services => }/code-runtime/value.ts (100%)
 rename packages/renderer-core/src/{services => }/extension/boosts.ts (95%)
 rename packages/renderer-core/src/{services => }/extension/extensionHostService.ts (83%)
 rename packages/renderer-core/src/{services => }/extension/index.ts (100%)
 rename packages/renderer-core/src/{services => }/extension/plugin.ts (93%)
 rename packages/renderer-core/src/{services => }/extension/render.ts (100%)
 create mode 100644 packages/renderer-core/src/intl/index.ts
 rename packages/renderer-core/src/{services/runtimeIntlService.ts => intl/intlService.ts} (94%)
 create mode 100644 packages/renderer-core/src/life-cycle/index.ts
 rename packages/renderer-core/src/{services => life-cycle}/lifeCycleService.ts (100%)
 rename packages/renderer-core/src/{services => }/model/componentTreeModel.ts (97%)
 rename packages/renderer-core/src/{services => }/model/componentTreeModelService.ts (98%)
 rename packages/renderer-core/src/{services => }/model/index.ts (100%)
 rename packages/renderer-core/src/{services => }/package/index.ts (100%)
 rename packages/renderer-core/src/{services => }/package/managementService.ts (99%)
 rename packages/renderer-core/src/{services => }/package/package.ts (100%)
 rename packages/renderer-core/src/{services => }/schema/index.ts (100%)
 rename packages/renderer-core/src/{services => }/schema/schemaService.ts (95%)
 rename packages/renderer-core/src/{services => }/schema/validation.ts (100%)
 delete mode 100644 packages/renderer-core/src/types.ts
 create mode 100644 packages/renderer-core/src/util/index.ts
 rename packages/renderer-core/src/{services/runtimeUtilService.ts => util/utilService.ts} (96%)

diff --git a/packages/react-renderer/src/runtime/createComponent.tsx b/packages/react-renderer/src/runtime/createComponent.tsx
index 4f42edbff..6e9f430e4 100644
--- a/packages/react-renderer/src/runtime/createComponent.tsx
+++ b/packages/react-renderer/src/runtime/createComponent.tsx
@@ -116,7 +116,6 @@ export function createComponent(
 
     useEffect(() => {
       // trigger lifeCycles
-      // componentDidMount?.();
       model.triggerLifeCycle('componentDidMount');
 
       // 当 state 改变之后调用
diff --git a/packages/react-renderer/src/runtime/elements.tsx b/packages/react-renderer/src/runtime/elements.tsx
index 3bafc53e9..98c21fd78 100644
--- a/packages/react-renderer/src/runtime/elements.tsx
+++ b/packages/react-renderer/src/runtime/elements.tsx
@@ -142,8 +142,7 @@ export function WidgetComponent(props: WidgetRendererProps) {
     },
   );
 
-  if (process.env.NODE_ENV === 'development') {
-    // development 模式下 把 widget 的内容作为 prop ,便于排查问题
+  if (__DEV__) {
     processedProps.widget = widget;
   }
 
diff --git a/packages/renderer-core/src/services/code-runtime/codeRuntime.ts b/packages/renderer-core/src/code-runtime/codeRuntime.ts
similarity index 97%
rename from packages/renderer-core/src/services/code-runtime/codeRuntime.ts
rename to packages/renderer-core/src/code-runtime/codeRuntime.ts
index 12c75581b..805b26506 100644
--- a/packages/renderer-core/src/services/code-runtime/codeRuntime.ts
+++ b/packages/renderer-core/src/code-runtime/codeRuntime.ts
@@ -53,7 +53,7 @@ export class CodeRuntime<T extends StringDictionary = StringDictionary>
     super();
 
     if (options.evalCodeFunction) this._evalCodeFunction = options.evalCodeFunction;
-    this._codeScope = this.addDispose(
+    this._codeScope = this._addDispose(
       options.parentScope
         ? options.parentScope.createChild<T>(options.initScopeValue ?? {})
         : new CodeScope(options.initScopeValue ?? {}),
@@ -122,7 +122,7 @@ export class CodeRuntime<T extends StringDictionary = StringDictionary>
   onResolve(handler: NodeResolverHandler): IDisposable {
     this._resolveHandlers.push(handler);
 
-    return this.addDispose(
+    return this._addDispose(
       toDisposable(() => {
         this._resolveHandlers = this._resolveHandlers.filter((h) => h !== handler);
       }),
@@ -132,7 +132,7 @@ export class CodeRuntime<T extends StringDictionary = StringDictionary>
   createChild<V extends StringDictionary = StringDictionary>(
     options?: Omit<CodeRuntimeOptions<V>, 'parentScope'>,
   ): ICodeRuntime<V> {
-    return this.addDispose(
+    return this._addDispose(
       new CodeRuntime({
         initScopeValue: options?.initScopeValue,
         parentScope: this._codeScope,
diff --git a/packages/renderer-core/src/services/code-runtime/codeRuntimeService.ts b/packages/renderer-core/src/code-runtime/codeRuntimeService.ts
similarity index 91%
rename from packages/renderer-core/src/services/code-runtime/codeRuntimeService.ts
rename to packages/renderer-core/src/code-runtime/codeRuntimeService.ts
index d329638e8..ab63e0aa0 100644
--- a/packages/renderer-core/src/services/code-runtime/codeRuntimeService.ts
+++ b/packages/renderer-core/src/code-runtime/codeRuntimeService.ts
@@ -29,8 +29,8 @@ export class CodeRuntimeService extends Disposable implements ICodeRuntimeServic
   ) {
     super();
 
-    this._rootRuntime = this.addDispose(new CodeRuntime(options));
-    this.addDispose(
+    this._rootRuntime = this._addDispose(new CodeRuntime(options));
+    this._addDispose(
       this.schemaService.onSchemaUpdate(({ key, data }) => {
         if (key === 'constants') {
           this.rootRuntime.getScope().set('constants', data);
@@ -44,7 +44,7 @@ export class CodeRuntimeService extends Disposable implements ICodeRuntimeServic
   ): ICodeRuntime<T> {
     this._throwIfDisposed();
 
-    return this.addDispose(
+    return this._addDispose(
       options.parentScope ? new CodeRuntime(options) : this.rootRuntime.createChild<T>(options),
     );
   }
diff --git a/packages/renderer-core/src/services/code-runtime/codeScope.ts b/packages/renderer-core/src/code-runtime/codeScope.ts
similarity index 97%
rename from packages/renderer-core/src/services/code-runtime/codeScope.ts
rename to packages/renderer-core/src/code-runtime/codeScope.ts
index 86537ace9..077b16a0a 100644
--- a/packages/renderer-core/src/services/code-runtime/codeScope.ts
+++ b/packages/renderer-core/src/code-runtime/codeScope.ts
@@ -66,7 +66,7 @@ export class CodeScope<T extends StringDictionary = StringDictionary>
   }
 
   createChild<V extends StringDictionary = StringDictionary>(initValue: Partial<V>): ICodeScope<V> {
-    const childScope = this.addDispose(new CodeScope(initValue));
+    const childScope = this._addDispose(new CodeScope(initValue));
     childScope.node.prev = this.node;
 
     return childScope;
diff --git a/packages/renderer-core/src/services/code-runtime/evaluate.ts b/packages/renderer-core/src/code-runtime/evaluate.ts
similarity index 100%
rename from packages/renderer-core/src/services/code-runtime/evaluate.ts
rename to packages/renderer-core/src/code-runtime/evaluate.ts
diff --git a/packages/renderer-core/src/services/code-runtime/globals-es2015.ts b/packages/renderer-core/src/code-runtime/globals-es2015.ts
similarity index 100%
rename from packages/renderer-core/src/services/code-runtime/globals-es2015.ts
rename to packages/renderer-core/src/code-runtime/globals-es2015.ts
diff --git a/packages/renderer-core/src/services/code-runtime/index.ts b/packages/renderer-core/src/code-runtime/index.ts
similarity index 100%
rename from packages/renderer-core/src/services/code-runtime/index.ts
rename to packages/renderer-core/src/code-runtime/index.ts
diff --git a/packages/renderer-core/src/services/code-runtime/value.ts b/packages/renderer-core/src/code-runtime/value.ts
similarity index 100%
rename from packages/renderer-core/src/services/code-runtime/value.ts
rename to packages/renderer-core/src/code-runtime/value.ts
diff --git a/packages/renderer-core/src/createRenderer.ts b/packages/renderer-core/src/createRenderer.ts
index 18d344f6f..5b9fb13aa 100644
--- a/packages/renderer-core/src/createRenderer.ts
+++ b/packages/renderer-core/src/createRenderer.ts
@@ -1,71 +1,98 @@
-import { invariant, InstantiationService } from '@alilc/lowcode-shared';
-import type { AppOptions, RendererApplication } from './types';
-import { CodeRuntimeService, ICodeRuntimeService } from './services/code-runtime';
+import {
+  invariant,
+  InstantiationService,
+  BeanContainer,
+  CtorDescriptor,
+  type Project,
+  type Package,
+} from '@alilc/lowcode-shared';
+import { CodeRuntimeService, ICodeRuntimeService, type CodeRuntimeOptions } from './code-runtime';
 import {
   IExtensionHostService,
   type RenderAdapter,
   type IRenderObject,
   ExtensionHostService,
-} from './services/extension';
-import { IPackageManagementService, PackageManagementService } from './services/package';
-import { ISchemaService, SchemaService } from './services/schema';
-import { ILifeCycleService, LifecyclePhase, LifeCycleService } from './services/lifeCycleService';
-import { IRuntimeIntlService, RuntimeIntlService } from './services/runtimeIntlService';
-import { IRuntimeUtilService, RuntimeUtilService } from './services/runtimeUtilService';
+  type Plugin,
+} from './extension';
+import { IPackageManagementService, PackageManagementService } from './package';
+import { ISchemaService, SchemaService } from './schema';
+import { ILifeCycleService, LifecyclePhase, LifeCycleService } from './life-cycle';
+import { IRuntimeIntlService, RuntimeIntlService } from './intl';
+import { IRuntimeUtilService, RuntimeUtilService } from './util';
+import { type ModelDataSourceCreator } from './model';
+
+export interface AppOptions {
+  schema: Project;
+  packages?: Package[];
+  plugins?: Plugin[];
+  /**
+   * code runtime 设置选项
+   */
+  codeRuntime?: CodeRuntimeOptions;
+  /**
+   * 数据源创建工厂函数
+   */
+  dataSourceCreator?: ModelDataSourceCreator;
+}
+
+export type RendererApplication<Render = unknown> = {
+  readonly mode: 'development' | 'production';
+
+  readonly schema: Omit<ISchemaService, 'initialize'>;
+
+  readonly packageManager: IPackageManagementService;
+
+  use(plugin: Plugin): Promise<void>;
+
+  destroy(): void;
+} & Render;
 
 export function createRenderer<RenderObject = IRenderObject>(
   renderAdapter: RenderAdapter<RenderObject>,
 ): (options: AppOptions) => Promise<RendererApplication<RenderObject>> {
   invariant(typeof renderAdapter === 'function', 'The first parameter must be a function.');
 
-  const instantiationService = new InstantiationService();
-
-  // create services
-  const lifeCycleService = new LifeCycleService();
-  instantiationService.container.set(ILifeCycleService, lifeCycleService);
-
   return async (options) => {
+    // create services
+    const container = new BeanContainer();
+    const lifeCycleService = new LifeCycleService();
+    container.set(ILifeCycleService, lifeCycleService);
+
     const schemaService = new SchemaService(options.schema);
-    instantiationService.container.set(ISchemaService, schemaService);
+    container.set(ISchemaService, schemaService);
 
-    const codeRuntimeService = instantiationService.createInstance(
-      CodeRuntimeService,
-      options.codeRuntime,
+    container.set(
+      ICodeRuntimeService,
+      new CtorDescriptor(CodeRuntimeService, [options.codeRuntime]),
     );
-    instantiationService.container.set(ICodeRuntimeService, codeRuntimeService);
-
-    const packageManagementService = instantiationService.createInstance(PackageManagementService);
-    instantiationService.container.set(IPackageManagementService, packageManagementService);
+    container.set(IPackageManagementService, new CtorDescriptor(PackageManagementService));
 
     const utils = schemaService.get('utils');
-    const runtimeUtilService = instantiationService.createInstance(RuntimeUtilService, utils);
-    instantiationService.container.set(IRuntimeUtilService, runtimeUtilService);
+    container.set(IRuntimeUtilService, new CtorDescriptor(RuntimeUtilService, [utils]));
 
     const defaultLocale = schemaService.get('config.defaultLocale');
     const i18ns = schemaService.get('i18n', {});
-    const runtimeIntlService = instantiationService.createInstance(
-      RuntimeIntlService,
-      defaultLocale,
-      i18ns,
-    );
-    instantiationService.container.set(IRuntimeIntlService, runtimeIntlService);
-
-    const extensionHostService = new ExtensionHostService(
-      lifeCycleService,
-      packageManagementService,
-      schemaService,
-      codeRuntimeService,
-      runtimeIntlService,
-      runtimeUtilService,
+    container.set(
+      IRuntimeIntlService,
+      new CtorDescriptor(RuntimeIntlService, [defaultLocale, i18ns]),
     );
-    instantiationService.container.set(IExtensionHostService, extensionHostService);
+
+    container.set(IExtensionHostService, new CtorDescriptor(ExtensionHostService));
+
+    const instantiationService = new InstantiationService(container);
 
     lifeCycleService.setPhase(LifecyclePhase.OptionsResolved);
 
+    const [extensionHostService, packageManagementService] = instantiationService.invokeFunction(
+      (accessor) => {
+        return [accessor.get(IExtensionHostService), accessor.get(IPackageManagementService)];
+      },
+    );
+
     const renderObject = await renderAdapter(instantiationService);
 
     await extensionHostService.registerPlugin(options.plugins ?? []);
-    // 先加载插件提供 package loader
+
     await packageManagementService.loadPackages(options.packages ?? []);
 
     lifeCycleService.setPhase(LifecyclePhase.Ready);
diff --git a/packages/renderer-core/src/services/extension/boosts.ts b/packages/renderer-core/src/extension/boosts.ts
similarity index 95%
rename from packages/renderer-core/src/services/extension/boosts.ts
rename to packages/renderer-core/src/extension/boosts.ts
index d13079d33..ddc2eeb3d 100644
--- a/packages/renderer-core/src/services/extension/boosts.ts
+++ b/packages/renderer-core/src/extension/boosts.ts
@@ -1,8 +1,8 @@
 import { type StringDictionary } from '@alilc/lowcode-shared';
 import { isObject } from 'lodash-es';
 import { ICodeRuntime, ICodeRuntimeService } from '../code-runtime';
-import { IRuntimeUtilService } from '../runtimeUtilService';
-import { IRuntimeIntlService } from '../runtimeIntlService';
+import { IRuntimeUtilService } from '../util/utilService';
+import { IRuntimeIntlService } from '../intlService';
 
 export type IBoosts<Extends> = IBoostsApi & Extends & { [key: string]: any };
 
diff --git a/packages/renderer-core/src/services/extension/extensionHostService.ts b/packages/renderer-core/src/extension/extensionHostService.ts
similarity index 83%
rename from packages/renderer-core/src/services/extension/extensionHostService.ts
rename to packages/renderer-core/src/extension/extensionHostService.ts
index 5533770c3..c207424fb 100644
--- a/packages/renderer-core/src/services/extension/extensionHostService.ts
+++ b/packages/renderer-core/src/extension/extensionHostService.ts
@@ -3,10 +3,10 @@ import { type Plugin, type PluginContext } from './plugin';
 import { BoostsManager } from './boosts';
 import { IPackageManagementService } from '../package';
 import { ISchemaService } from '../schema';
-import { ILifeCycleService } from '../lifeCycleService';
+import { ILifeCycleService } from '../life-cycle/lifeCycleService';
 import { ICodeRuntimeService } from '../code-runtime';
-import { IRuntimeIntlService } from '../runtimeIntlService';
-import { IRuntimeUtilService } from '../runtimeUtilService';
+import { IRuntimeIntlService } from '../intl';
+import { IRuntimeUtilService } from '../util';
 
 export interface IExtensionHostService {
   readonly boostsManager: BoostsManager;
@@ -28,12 +28,12 @@ export class ExtensionHostService extends Disposable implements IExtensionHostSe
   private _pluginSetupContext: PluginContext;
 
   constructor(
-    lifeCycleService: ILifeCycleService,
-    packageManagementService: IPackageManagementService,
-    schemaService: ISchemaService,
-    codeRuntimeService: ICodeRuntimeService,
-    runtimeIntlService: IRuntimeIntlService,
-    runtimeUtilService: IRuntimeUtilService,
+    @ILifeCycleService lifeCycleService: ILifeCycleService,
+    @IPackageManagementService packageManagementService: IPackageManagementService,
+    @ISchemaService schemaService: ISchemaService,
+    @ICodeRuntimeService codeRuntimeService: ICodeRuntimeService,
+    @IRuntimeIntlService runtimeIntlService: IRuntimeIntlService,
+    @IRuntimeUtilService runtimeUtilService: IRuntimeUtilService,
   ) {
     super();
 
@@ -103,7 +103,7 @@ export class ExtensionHostService extends Disposable implements IExtensionHostSe
 
     await plugin.setup(this._pluginSetupContext);
     this._activePlugins.add(plugin.name);
-    this.addDispose(plugin);
+    this._addDispose(plugin);
   }
 
   getPlugin(name: string): Plugin | undefined {
diff --git a/packages/renderer-core/src/services/extension/index.ts b/packages/renderer-core/src/extension/index.ts
similarity index 100%
rename from packages/renderer-core/src/services/extension/index.ts
rename to packages/renderer-core/src/extension/index.ts
diff --git a/packages/renderer-core/src/services/extension/plugin.ts b/packages/renderer-core/src/extension/plugin.ts
similarity index 93%
rename from packages/renderer-core/src/services/extension/plugin.ts
rename to packages/renderer-core/src/extension/plugin.ts
index 3e94310d5..863fa6fa3 100644
--- a/packages/renderer-core/src/services/extension/plugin.ts
+++ b/packages/renderer-core/src/extension/plugin.ts
@@ -1,6 +1,6 @@
 import { type StringDictionary, type IDisposable } from '@alilc/lowcode-shared';
 import { type IBoosts } from './boosts';
-import { ILifeCycleService } from '../lifeCycleService';
+import { ILifeCycleService } from '../life-cycle/lifeCycleService';
 import { type ISchemaService } from '../schema';
 import { type IPackageManagementService } from '../package';
 import { type IStore } from '../../utils/store';
diff --git a/packages/renderer-core/src/services/extension/render.ts b/packages/renderer-core/src/extension/render.ts
similarity index 100%
rename from packages/renderer-core/src/services/extension/render.ts
rename to packages/renderer-core/src/extension/render.ts
diff --git a/packages/renderer-core/src/index.ts b/packages/renderer-core/src/index.ts
index 58b9135c4..cad42f4e9 100644
--- a/packages/renderer-core/src/index.ts
+++ b/packages/renderer-core/src/index.ts
@@ -1,21 +1,20 @@
 /* --------------- api -------------------- */
-export { createRenderer } from './createRenderer';
-export { IExtensionHostService } from './services/extension';
-export { definePackageLoader, IPackageManagementService } from './services/package';
-export { LifecyclePhase, ILifeCycleService } from './services/lifeCycleService';
-export { IComponentTreeModelService } from './services/model';
-export { ICodeRuntimeService } from './services/code-runtime';
-export { IRuntimeIntlService } from './services/runtimeIntlService';
-export { IRuntimeUtilService } from './services/runtimeUtilService';
-export { ISchemaService } from './services/schema';
+export * from './createRenderer';
+export { IExtensionHostService } from './extension';
+export { definePackageLoader, IPackageManagementService } from './package';
+export { LifecyclePhase, ILifeCycleService } from './life-cycle';
+export { IComponentTreeModelService } from './model';
+export { ICodeRuntimeService, mapValue, someValue } from './code-runtime';
+export { IRuntimeIntlService } from './intl';
+export { IRuntimeUtilService } from './util';
+export { ISchemaService } from './schema';
 export { Widget } from './widget';
 
 /* --------------- types ---------------- */
-export type * from './types';
-export type * from './services/extension';
-export type * from './services/code-runtime';
-export type * from './services/model';
-export type * from './services/package';
-export type * from './services/schema';
-export type * from './services/extension';
+export type * from './extension';
+export type * from './code-runtime';
+export type * from './model';
+export type * from './package';
+export type * from './schema';
+export type * from './extension';
 export type * from './widget';
diff --git a/packages/renderer-core/src/intl/index.ts b/packages/renderer-core/src/intl/index.ts
new file mode 100644
index 000000000..725ac0533
--- /dev/null
+++ b/packages/renderer-core/src/intl/index.ts
@@ -0,0 +1 @@
+export * from './intlService';
diff --git a/packages/renderer-core/src/services/runtimeIntlService.ts b/packages/renderer-core/src/intl/intlService.ts
similarity index 94%
rename from packages/renderer-core/src/services/runtimeIntlService.ts
rename to packages/renderer-core/src/intl/intlService.ts
index 205a45e9f..8c0ad7cd6 100644
--- a/packages/renderer-core/src/services/runtimeIntlService.ts
+++ b/packages/renderer-core/src/intl/intlService.ts
@@ -7,7 +7,7 @@ import {
   type LocaleTranslationsMap,
   Disposable,
 } from '@alilc/lowcode-shared';
-import { ICodeRuntimeService } from './code-runtime';
+import { ICodeRuntimeService } from '../code-runtime';
 
 export interface MessageDescriptor {
   key: string;
@@ -37,7 +37,7 @@ export class RuntimeIntlService extends Disposable implements IRuntimeIntlServic
   ) {
     super();
 
-    this._intl = this.addDispose(new Intl(defaultLocale));
+    this._intl = this._addDispose(new Intl(defaultLocale));
     for (const key of Object.keys(i18nTranslations)) {
       this._intl.addTranslations(key, i18nTranslations[key]);
     }
diff --git a/packages/renderer-core/src/life-cycle/index.ts b/packages/renderer-core/src/life-cycle/index.ts
new file mode 100644
index 000000000..c3ec2d63e
--- /dev/null
+++ b/packages/renderer-core/src/life-cycle/index.ts
@@ -0,0 +1 @@
+export * from './lifeCycleService';
diff --git a/packages/renderer-core/src/services/lifeCycleService.ts b/packages/renderer-core/src/life-cycle/lifeCycleService.ts
similarity index 100%
rename from packages/renderer-core/src/services/lifeCycleService.ts
rename to packages/renderer-core/src/life-cycle/lifeCycleService.ts
diff --git a/packages/renderer-core/src/services/model/componentTreeModel.ts b/packages/renderer-core/src/model/componentTreeModel.ts
similarity index 97%
rename from packages/renderer-core/src/services/model/componentTreeModel.ts
rename to packages/renderer-core/src/model/componentTreeModel.ts
index 89ff757b6..951fdd662 100644
--- a/packages/renderer-core/src/services/model/componentTreeModel.ts
+++ b/packages/renderer-core/src/model/componentTreeModel.ts
@@ -15,7 +15,7 @@ import {
   Disposable,
 } from '@alilc/lowcode-shared';
 import { type ICodeRuntime } from '../code-runtime';
-import { IWidget, Widget } from '../../widget';
+import { IWidget, Widget } from '../widget';
 
 export interface NormalizedComponentNode extends ComponentNode {
   loopArgs: [string, string];
@@ -25,7 +25,7 @@ export interface NormalizedComponentNode extends ComponentNode {
 /**
  * 根据低代码搭建协议的容器组件描述生成的容器模型
  */
-export interface IComponentTreeModel<Component, ComponentInstance = unknown> {
+export interface IComponentTreeModel<Component, ComponentInstance = unknown> extends IDisposable {
   readonly id: string;
 
   readonly codeRuntime: ICodeRuntime;
@@ -61,7 +61,7 @@ export type ModelDataSourceCreator = (
   codeRuntime: ICodeRuntime<InstanceApi>,
 ) => InstanceDataSourceApi;
 
-export interface ComponentTreeModelOptions extends IDisposable {
+export interface ComponentTreeModelOptions {
   id?: string;
   metadata?: StringDictionary;
 
@@ -91,7 +91,7 @@ export class ComponentTreeModel<Component, ComponentInstance = unknown>
     this._id = options?.id ?? `model_${uniqueId()}`;
     this._metadata = options?.metadata ?? {};
     this.initialize(options);
-    this.addDispose(_codeRuntime);
+    this._addDispose(_codeRuntime);
   }
 
   get id() {
diff --git a/packages/renderer-core/src/services/model/componentTreeModelService.ts b/packages/renderer-core/src/model/componentTreeModelService.ts
similarity index 98%
rename from packages/renderer-core/src/services/model/componentTreeModelService.ts
rename to packages/renderer-core/src/model/componentTreeModelService.ts
index cd09a7898..90b7048c3 100644
--- a/packages/renderer-core/src/services/model/componentTreeModelService.ts
+++ b/packages/renderer-core/src/model/componentTreeModelService.ts
@@ -48,7 +48,7 @@ export class ComponentTreeModelService extends Disposable implements IComponentT
   ): IComponentTreeModel<Component> {
     this._throwIfDisposed(`ComponentTreeModelService has been disposed.`);
 
-    return this.addDispose(
+    return this._addDispose(
       new ComponentTreeModel(
         componentsTree,
         this.codeRuntimeService.createCodeRuntime({
diff --git a/packages/renderer-core/src/services/model/index.ts b/packages/renderer-core/src/model/index.ts
similarity index 100%
rename from packages/renderer-core/src/services/model/index.ts
rename to packages/renderer-core/src/model/index.ts
diff --git a/packages/renderer-core/src/services/package/index.ts b/packages/renderer-core/src/package/index.ts
similarity index 100%
rename from packages/renderer-core/src/services/package/index.ts
rename to packages/renderer-core/src/package/index.ts
diff --git a/packages/renderer-core/src/services/package/managementService.ts b/packages/renderer-core/src/package/managementService.ts
similarity index 99%
rename from packages/renderer-core/src/services/package/managementService.ts
rename to packages/renderer-core/src/package/managementService.ts
index 3f66b7f9c..e269279ab 100644
--- a/packages/renderer-core/src/services/package/managementService.ts
+++ b/packages/renderer-core/src/package/managementService.ts
@@ -63,7 +63,7 @@ export class PackageManagementService extends Disposable implements IPackageMana
   constructor(@ISchemaService private schemaService: ISchemaService) {
     super();
 
-    this.addDispose(
+    this._addDispose(
       this.schemaService.onSchemaUpdate(({ key, previous, data }) => {
         if (key === 'componentsMap') {
           // todo: add remove ...
diff --git a/packages/renderer-core/src/services/package/package.ts b/packages/renderer-core/src/package/package.ts
similarity index 100%
rename from packages/renderer-core/src/services/package/package.ts
rename to packages/renderer-core/src/package/package.ts
diff --git a/packages/renderer-core/src/services/schema/index.ts b/packages/renderer-core/src/schema/index.ts
similarity index 100%
rename from packages/renderer-core/src/services/schema/index.ts
rename to packages/renderer-core/src/schema/index.ts
diff --git a/packages/renderer-core/src/services/schema/schemaService.ts b/packages/renderer-core/src/schema/schemaService.ts
similarity index 95%
rename from packages/renderer-core/src/services/schema/schemaService.ts
rename to packages/renderer-core/src/schema/schemaService.ts
index b736ea989..e3bd5046a 100644
--- a/packages/renderer-core/src/services/schema/schemaService.ts
+++ b/packages/renderer-core/src/schema/schemaService.ts
@@ -22,7 +22,7 @@ export const ISchemaService = createDecorator<ISchemaService>('schemaService');
 export class SchemaService extends Disposable implements ISchemaService {
   private store: NormalizedSchema;
 
-  private _observer = this.addDispose(new Events.Emitter<SchemaUpdateEvent>());
+  private _observer = this._addDispose(new Events.Emitter<SchemaUpdateEvent>());
 
   readonly onSchemaUpdate = this._observer.event;
 
diff --git a/packages/renderer-core/src/services/schema/validation.ts b/packages/renderer-core/src/schema/validation.ts
similarity index 100%
rename from packages/renderer-core/src/services/schema/validation.ts
rename to packages/renderer-core/src/schema/validation.ts
diff --git a/packages/renderer-core/src/types.ts b/packages/renderer-core/src/types.ts
deleted file mode 100644
index a2e00b598..000000000
--- a/packages/renderer-core/src/types.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-import { type Project, type Package } from '@alilc/lowcode-shared';
-import { type Plugin } from './services/extension';
-import { type ISchemaService } from './services/schema';
-import { type IPackageManagementService } from './services/package';
-import { type CodeRuntimeOptions } from './services/code-runtime';
-import { type ModelDataSourceCreator } from './services/model';
-
-export interface AppOptions {
-  schema: Project;
-  packages?: Package[];
-  plugins?: Plugin[];
-  /**
-   * code runtime 设置选项
-   */
-  codeRuntime?: CodeRuntimeOptions;
-  /**
-   * 数据源创建工厂函数
-   */
-  dataSourceCreator?: ModelDataSourceCreator;
-}
-
-export type RendererApplication<Render = unknown> = {
-  readonly mode: 'development' | 'production';
-
-  readonly schema: Omit<ISchemaService, 'initialize'>;
-
-  readonly packageManager: IPackageManagementService;
-
-  use(plugin: Plugin): Promise<void>;
-
-  destroy(): void;
-} & Render;
diff --git a/packages/renderer-core/src/util/index.ts b/packages/renderer-core/src/util/index.ts
new file mode 100644
index 000000000..b9d407dd3
--- /dev/null
+++ b/packages/renderer-core/src/util/index.ts
@@ -0,0 +1 @@
+export * from './utilService';
diff --git a/packages/renderer-core/src/services/runtimeUtilService.ts b/packages/renderer-core/src/util/utilService.ts
similarity index 96%
rename from packages/renderer-core/src/services/runtimeUtilService.ts
rename to packages/renderer-core/src/util/utilService.ts
index 9d8d2c88c..58ba3858d 100644
--- a/packages/renderer-core/src/services/runtimeUtilService.ts
+++ b/packages/renderer-core/src/util/utilService.ts
@@ -5,8 +5,8 @@ import {
   type StringDictionary,
 } from '@alilc/lowcode-shared';
 import { isPlainObject } from 'lodash-es';
-import { IPackageManagementService } from './package';
-import { ICodeRuntimeService } from './code-runtime';
+import { IPackageManagementService } from '../package';
+import { ICodeRuntimeService } from '../code-runtime';
 
 export interface IRuntimeUtilService {
   add(utilItem: UtilDescription, force?: boolean): void;