Angular 之外的主要和服务依赖关系

Main and Service Dependencies outside of Angular

提问人:Market 提问时间:11/16/2023 更新时间:11/16/2023 访问量:30

问:

如何从外部动态注入并运行Angular?为运行时服务注入寻求干净的架构解决方案。servicesAngular projectnpm project

我在同一级别有两个文件夹

  • angular-ui其中包含 angular 项目
  • main-project其中包含特定的服务定义。主要职责是像传统的项目一样注入所有依赖项。

我想在引导阶段运行我的并传递服务依赖项...... 像这样给你一个想法的东西main-project

// Instantiate Angular app
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule).then((moduleRef) => {
  // Get the Angular injector
  const injector = moduleRef.injector;

  // Create an instance of your service and inject it
  const exampleService = new ExampleService();
  injector.get(ExampleService).constructor = () => exampleService;

  // Continue with your application logic
});

依赖方向来自main-project ----> angular-ui

在“通用”的传统方式中,我曾经将我的具体服务添加到其他东西(新包)中,甚至引用其他东西(新包),这些服务提供了服务的具体实现。但是,这个方向打破了我原来的依赖架构。angarl-uiangular-ui

你能给我建议在这个方向上实现我的UI吗?

角度 依赖注入 关注点分离

评论


答: 暂无答案