Question

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"

Était-ce utile?

La solution

public static class Foo
{
    public static int Bar()
    {
        return 1;
    }

    public static void AddImage(Image img, String key){...}
    public static Image GetImage(String key){...}
}

Autres conseils

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

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top