应用设计、全球图像采集

发布于 2025-01-04 06:34:26 字数 776 浏览 1 评论 0原文

我们有一个类似 n 层结构的应用程序,但我不会说它是 n 层的。 最顶层的 Form /AKA MainForm/ 连接到数据库并获取可用模块的列表,根据该列表开始加载不同的模块。每个模块都是一个单独的项目,具有 1 个从抽象类派生的顶级类,所有模块都从该抽象类派生。

如此往复,到目前为止,我们一切都运行得很好,在模块和主应用程序之间传递连接字符串、对话框。

下一步是实现每个模块都要使用的全局图标库,问题是每个模块应该能够向其中加载自己的图像。

我正在考虑一个全局静态类,它返回当前正在运行的 ImageList 类的实例。我不知道从哪里开始,所以有人可以提供一个可以静态使用而无需声明或传递它的全局类的示例吗?这有可能吗?

编辑:
改写尝试:理想情况下,每个单独的模块都能够向其中插入资源的全局资源,每个模块都能够从中获取图像(如果存在)。我什至不知道从哪里开始或寻找什么。

编辑2:

刚刚检查:
有 3 个项目:1 个主项目、1 个子项目、1 个中间项目
其间主要参考文献
子引用 in Between

1 main 启动并调用“in Between”上的静态方法,将一些字符串加载到其中。使用反射“main”实例加载 child.dll 并使用反射实例化该对象,然后调用子对象上“in Between”中接口中定义的方法,该方法又调用“in Between”上的静态方法,之后“main” " 打印静态“in Between”中的所有字符串。它有效!我当时就想WTF?我猜反思结合了两个“中间”

We have an application, n-tier like structured, but I wouldn't say it's n-tiered.
The top most Form /AKA MainForm/ connects to a DB and gets a list of available modules, according to which it starts loading different modules. Each module is a separate project having 1 top level class that derives from an abstract class, from which all modules derive.

So on and on, so far we have everything running just fine, passing around connections strings, dialogs between modules and the main app.

the next step is to implement a global icon library that each module is to use, the catch is that each module should be able to load its own images to it.

I'm thinking of a global static class that returns currently running instance of ImageList class. I don't know where to start with that, so could anyone please provide an example of global Class that could be used statically without the need of declaring or passing it around? is it possible at all?

EDIT:
rephrase attempt: ideally a global resource to which each separate module is able to insert resources, out of which each module is able to get images if they exist. I don't even know where to start or what to look for.

EDIT 2:

just checked:
had 3 projects: 1 main, 1 child, 1 inbetween
main references inbetween
child references inbetween

1 main starts and calls static methods on "inbetween" loading some strings into it. Using Reflection "main" instance loads child.dll and instantiates the object using the reflection, then calls a method defined in an interface in "inbetween" on the child obj which in turn calls the static method on the "inbetween" after which "main" prints all the strings in the static "inbetween". And it works! I was like WTF? I guess Reflection combines the 2 "inbetweens"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2025-01-11 06:34:26
public static class Foo
{
    public static int Bar()
    {
        return 1;
    }

    public static void AddImage(Image img, String key){...}
    public static Image GetImage(String key){...}
}
public static class Foo
{
    public static int Bar()
    {
        return 1;
    }

    public static void AddImage(Image img, String key){...}
    public static Image GetImage(String key){...}
}
夏の忆 2025-01-11 06:34:26

那么,您的意思是您需要一个“模块静态”(行为类似于线程静态但针对模块)方法?

So, you mean u need a "module static" (behaves like thread static but aim at module) method?

白芷 2025-01-11 06:34:26

一种简单的方法是拥有一个每个模块都可以引用的共享库。因此每个模块都会知道共享库提供的类的存在。然后,您可以在该共享库中拥有一个类来管理您的图像。

为了使它更优雅,我会研究像 Unity 这样的依赖注入框架。让共享库(基础设施库)保存管理图像的接口的定义。然后有一个实现该特定接口的模块,然后在统一容器中注册该实现者。因此每个模块都会通过统一容器来解析接口。

这样,每个模块并不与实现接口的模块紧密耦合,而仅与仅包含接口定义的共享库紧密耦合。

One easy way would have a shared library that each module would have a reference to. So each module would know the existence of the class offered by the shared library. You could then have a class in that shared library to manage your images.

To make it more elegant, I would look into Dependency Injection framework like Unity. Have the shared library (infrastructure library) hold the definition of an Interface to manage images. Then have a module that implements that specific interface and then register that implementater in the unity container. So each module would go through the unity container to RESOLVE the Interface.

this way each module are not tightly coupled to the module that implements the interface but only to the shared library which only contains the definition of the interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文