Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I share Business Layer classes between a desktop App and a Web App in c#?

Tags:

c#

I guess I need to create an Assembly but how do I do this concretely when I have multiple classes ? There seems to be many steps involved and searching on the net I cannot find any article on this subject. Can anyone point me to one if it exists ?

like image 831
user310291 Avatar asked Dec 13 '22 19:12

user310291


2 Answers

Create a new project of type "Class Library", and put you business layer classes in it. Then reference it from your web app and your desktop app.

like image 60
Thomas Levesque Avatar answered Dec 15 '22 08:12

Thomas Levesque


You have to create a new project of Class Library type, and put you shared classes there. When you compile such type of project, you get a dll file in the output folder (the output folder, if you didn't change the default, is bin\debug or bin\release, relative to your project folder)

Than, you have to reference this dll from your web app and and your desktop app.

However, if you're using Visual Studio, another option is to use the "project reference" feature. If you put all your 3 projects in the same solution, you can tell your web app and and your desktop app to reference the class library project, not directly the dll. If you reerence this way, VS take care of recompile your business dll whenever it is needed. With the first option you have to remember to manually recompile the business project whenever you edit it, otherwise your UI project still reference the old version of the dll .

like image 30
Andrea Parodi Avatar answered Dec 15 '22 08:12

Andrea Parodi