Shared Code Between Multiple Asp.Net projects [duplicate]

夙愿已清 提交于 2019-12-05 15:12:48

Best practice would suggest you don't.

Each application is different, treat them as such. By sharing resources you create an implicit dependency between the projects - if you change a shared resource you are changing it for all - whether it was intended or not.

If you really must share resources, do it at the level of source control or builds - it is far easier to break the dependency at that level than it is to break the dependency once you have it deployed on a production server.


Xanadont, sharing common libraries etc is fine ( this is essentially what open source projects like nHibernate do ), but doing this at the level of bin sharing folders on a production server creates more problems than it solves. The kind of re-use you are talking about is best approached by creating shared libraries that are independent projects within source control with binary versions maintained somewhere. Projects wishing to use the shared libraries then take a binary dependency on the shared library by copying the binary into the lib folder of the solutions source tree and referencing that binary. This allows the shared libraries to be maintained and updated without causing side-effects due to direct dependencies on them, and solutions that use the libraries can evaluate the fixes / updates to determine how they will impact the code that depends on them and if the upgrade is worthwhile.


Scott, what you are referring to is 1 application with variations in the view layer (templates), not 50 applications with variations in the business logic. The best approach for this kind of application is multi-tenanting ( as I assume you have 1 database per city as well ) and use the url to define a context from within which you can access your database and resolve your view paths ( hard to describe a better approach without understanding your application architecture better ).

Changing views based on the url could be done by implementing a context aware view engine ( see http://www.coderjournal.com/2009/05/creating-your-first-mvc-viewengine/ for an example of how to do this.

With this kind of approach, you have only 1 location that you need to update with fixes, yet you can easily create a new "site" for another city just by adding a new set of templates and ( depending on how you set the routing up ) pointing the new domain at your site. If you have a set of default templates, your view engine could even fall back to these if customisations do not exist, therefore allowing you to set up a new site just by pointing a new domain at your application.

I use the following technique: I have multiple ASP.net application projects with ascx controls, resources and so on...I've implemented virtual path provider to resolve virtual paths between these applications. It works very well. I've also implemented special http handler to make files downloadable. If you need samples, look at liveui source code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!