开发者

How do I share Business Layer classes between a desktop App and a Web App in 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 o开发者_StackOverflowne if it exists ?


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.


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 .


Create a new "Class Library" project.
Write business layer there.
Share the output dll in your web app and desktop app.


You can have multiple classes in a single assembly. (As others have pointed out, you want to select the Class Library project type). Then just reference this assembly from your web and desktop apps. (either as a project reference if you put them in the same solution, or by browsing to the compiled dll otherwise)


I would suggest reading Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries

Enjoy!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜