My Adsense

Sunday, September 16, 2012

Using Dependency Injection (Unity) to Launch Windows Form Application Part 2

We have successfully removed the dependency between the Form to be launched with the Application.Run method of the Program.cs file of another project in my previous post.
Now we will do some testing on how can we add the other forms with this existing compiled executable file (exe) without rebuilding it. It is important because there will be many cases where you will be sitting on the client side for deployment and you don't have access to your development environment. You will just get the updated DLL of the new form. So how can we do that smartly?

Lets create another project (not inside of the solution we made in the first part) added the word External in the name.

As we did in the previous post, Delete the Program.cs file, Rename the Form's name, and make the project as Class Library type instead of Windows Forms Application on Start Up. 
Then add a Label on the Form and write some text in it. After doing these steps, the project will be look like the following image.

Build this project and copy the DLL of this project.

Paste that DLL in our Main Project's Debug Folder shown in the below image.

Since in this stage, we want to open the Windows Form under the External DLL file, we should change the MainProject's config file using a text editor e.g. notepad. 

Change the config file as below.

Now double click the exe we made before. The newly added Form will be opened.

I hope you all understand what we did. If you find any kinds of problem in understanding any step I mentioned, feel free to add comment under the blog. 

No comments: