Short background: I\'m using MEF/C# for developing a program that has one core (
ID: 643880 • Letter: S
Question
Short background: I'm using MEF/C# for developing a program that has one core (singleton) and multiple MEF parts (I call them modules, each module is a separate assembly with one class that contains the MEF export). The core imports all parts that are needed/available and initializes them (makes them read their configuration files, that stuff happens in the constructors, business as usual)
Now, my problem is that I need modules to interact with each other (say, module A, a graphical user interface, needs to get some data from a database, it'd need to somehow call a function on the database module (module B).)
How'd I do that? Sure, I could just make those parts/modules public in my core, add a reference to the core in my module and be done with it, but somehow, that'd feel ugly/bad. (mainly because I've security concerns over such an implementation, everyone could just call that function, unless I use something like this, but still it doesn't feel right).
Another approach would be to put all of those functions into the core, where they just call the corresponding function of the module. That feels bad, too because I'd have to add a lot of stuff to my core and in some cases that'd be something that a potential customer won't ever use because he doesn't need/have the specific module.
Does anyone know a better method of doing this? Maybe my train of thought went completely wrong somewhere?
Explanation / Answer
module A, a graphical user interface, needs to get some data from a database
This is indicative of an incorrect module design.
The point of dividing the code into modules is compartmentalization of functionality. This means that each module should have a specific area of functionality, and do that only.
A GUI module should only handle the user interface.
A database module should only interact with the database.
Passing information from one to the other should happen at a higher level. This might be your core module. Or, depending on what you are trying to do, it might make sense to add another layer.
Example:
If the user clicks on a button "Get my Data", an event handler in the GUI module calls a core method requesting data. This core method then calls the database module to get the data.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.