I'm building an application using C#/WCF. There will be a main form project is essentially the thing that connects all the other projects (DLLs) and the DLLs are not aware or allowed to reference each other. However in one DLL, say the patient dll, there is a form with a button and when that button is clicked it needs to open a form in a different dll say the rx dll but the two DLL's can't reference each other they are only connected via the main form.
So I was wondering if it's possible to accomplish a task like that and if so how to go about it. I would prefer not to use a message queue or send message if possible.
Th开发者_开发问答anks for any advice or help.
You can link the forms with an event:
Add this to the form with the button:
public event Action OpenOtherFormClick;
button_Click (object sender, EventArgs e) //Link to the button's Click event...
{
if (OpenOtherFormClick != null) { OpenOtherFormClick()}
}
Add this to the main project:
instanceOfFormWithButton.OpenOtherFormClick += () =>
{
//Open other form, e.g.
new OtherForm().Show();
//or
new OtherForm().ShowDialog();
//or, with factory class:
FormFactory.ShowOtherForm();
};
alternatively:
instanceOfFormWithButton.OpenOtherFormClick += FormFactory.ShowOtherForm;
The factory has the advantage that you can restrict certain forms to a single instance, for example to show a detail form only once and only focus it if it's already open.
I am not sure if I truly understand your question, but you might take a look at MEF.
However you can use WCF for interprocess communication (net.pipe), it's not a good practice.
精彩评论