3

I have 3 projects: UI, Core and Host, windows forms, class library and windows forms respectively.

UI is my startup project but the setting for Start external program is Host.exe.

UI has a reference to the Core project which is my data-access layer.

Host is the one loading the configurations.

Basically, when I run the application, the first thing that is executed is the Main function of the Host project.

Now, within the Main function, I'd like to get data from the database but Host has no reference to Core.

How do I get data from the database when my Main function is executed?

Currently, what I can think of is execute something (batch file or tt) on my Main function and write to a file. From the file, I will get my data. Can you suggest other ways to do this?

jmc
  • 1,649
  • 6
  • 26
  • 47
  • Surely the simplest way is to add a reference to Core from Host? – James Mar 31 '15 at 08:27
  • To expand on @JamesBarrass coment why does the Host project even exist? Why not just have the Main in your UI project? – Bas Bossink Mar 31 '15 at 08:43
  • I'll try my best to explain. These 3 projects are part of solution that contains a lot of other projects. Basically, the Host just contains the main form and empty controls. All the modules are within the UI project, e.g Customer Management Module. What the Host does is configuring the main form so that when you go to the Customer Management Module, all the buttons, labels, etc, are stuffed in to the empty control that I mentioned. Basically, the Host is there to configure the main form as a template. And no, I cant add a reference to Core from Host. – jmc Mar 31 '15 at 09:12

1 Answers1

0

If Host has reference to UI you can create a public class / method in UI which host will be able to consume.

if UI has a reference to Host and Host has no reference to UI, you could still do something like that by using interfaces, say you add another project called "Interfaces" and in there you create an interface "IProvideDBAccess" for example, host will reference that assembly.

UI will contain a public class which will implement the interface "IProvideDBAccess" and host will be able to use any object retrieved at run-time which implements that interface even with no strong reference to UI.

of course there are many other way to accomplish what you would like to do surely without saving a text file and parsing it again ;-)

Have a look here as well for some project or solution layering ideas, just as ideas I know it is not totally what you are looking for in your specific case: https://stackoverflow.com/a/7474357/559144

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • 1
    Hi Davide, I have implemented what you have mentioned in paragraphs 2 and 3. Could you possibly show me some code on how to use the public class that implemented "IProvideDBAccess" on my Host project? – jmc Mar 31 '15 at 09:26
  • @wintersolstice please share with us how the Host project is loading the UI project in its Main method, edit your question above to show us some code. Thanks. – Davide Piras Mar 31 '15 at 09:29
  • Ok I will edit in a while. Referring to paragraph 3 of your answer, let's say the public class I created is named "ApplicationClass". In my main function, can I say IProvideDBAccess access = new ApplicationClass(); ? I'm quite confused how I might be able to use it since Host has no reference to UI and ApplicationClass : IProvideDBAccess was implemented on UI – jmc Mar 31 '15 at 09:41