AIR书面申请使用需要单身产卵应用程序的多个实例 [英] AIR Application written using Singletons needs to spawn multiple instances of app

查看:196
本文介绍了AIR书面申请使用需要单身产卵应用程序的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用单身在整个应用程序管理全局状态AIR应用程序。伟大的作品为它做什么(管理网络设备)。但是,现在客户想产卵多个应用程序实例的第一个实例,使他们能够在同一时间处理多个硬件设备......有点像仪表板,但很多更大。

I have an AIR application that uses Singletons to manage global state throughout the application. Works great for what it does (manages a network appliance). But now the client wants to spawn multiple application instances from the first instance so they can manage multiple hardware devices at the same time ... kind of like a dashboard but lots bigger.

正如您可以猜到,我codeD自己与单身一个角落,所以如果我重构应用程序有启动应用程序的逻辑和一个按钮引导类,让我们说,会派生包含另一个窗口同一个应用程序的逻辑,那么单身跨两个应用窗口共享,而我也希望两个单独的实例。

As you can guess, I coded myself into a corner with the singletons so if I refactor the application to have a bootstrap class that launches the application logic with a button, let's say, that spawns another window that contains the same application logic, then the singletons are shared across both app windows whereas I would have liked two separate instances.

有没有办法使用的单身(或别的东西),以保持全球状态,但创建多个实例,每个实例都需要它自己的状态管理器?一个应用程序

Is there a way to use singletons ( or something else ) to keep global state but create multiple instances in one application where each instance needs it's own state manager?

推荐答案

有几种不同的选择:

  1. 在加载每个应用程序实例到它自己的的ApplicationDomain
  2. 使用一个依赖注入框架,你不要T获得单 - 而不是这个它的值分配给在运行的类属性。所有的东西是由元数据管理。这将需要一些code的变化。
  3. 在重构你的code,使每个类的实例会知道它的背景。这可以通过添加一个构造函数的参数或 setContext实施(价值:上下文)功能。 上下文实例会包含链接到所有你的前单身。
  4. 转到了显示列表,直到你找到一些类实例,可以提供你的前单身的链接。确保每个非显示列表对象有一个链接到显示列表对象来获取单身了。
  1. Load each application instance into it's own ApplicationDomain
  2. Use one of the dependency injection frameworks where you don't get the singleton - instead of this it's value is assigned to your class property in runtime. All the stuff is managed by the metadata. It would require some code changes.
  3. Refactor your code so that each class instance would know it's context. This can be implementing by adding a constructor parameter or setContext(value:Context) function. Context instance will contain links to all your ex-singletons.
  4. Go up the display list until you find some class instance that can provide you the links to ex-singletons. Make sure that each non-display-list object has a link to display list object to get singletons too.

这篇关于AIR书面申请使用需要单身产卵应用程序的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆