views:

463

answers:

3

What's the best practice to share the bin folder and dlls and other resource files (like css) between multiple web applications on the same server?

I've already separated out the common code into their own assemblies, but I'm wondering about deployment, etc. I basically want to have all the common files located in ONE location on the webserver, and then have each web app reference that common location.

Currently I'm not sure how to tell an Asp.net website to use the bin folder from a different location.

If it makes any difference, these are ASP.NET MVC applications.

Thanks for you help.

+1  A: 

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.

Neal
I don't agree. Sharing common functionality and resources is the whole idea behind code libraries. It's the same reason why you have the .Net platform - lots of common functionality nicely bundled into the framework. Why not extend this idea to common functionality for your organization? Consider the scenario of plugging a security hole - do so in the "shared resource" environment and you take care of everything in one place. Otherwise you risk accidentally forgetting the update of one of your sites and now you have a problem. In the worst case this could be extremely dangerous.
xanadont
I'm sharing because this is the same web application, across multiple cities. So, ALL the functionality is the same, but each city will have a slightly modified HTML front end. To me, duplicating all the unchanging middle-tier code over and over is amateurish. What happens when I have 50 cities and I need to make a small change the DB? I have to update the dlls in 50 independent bin folders? I realize I can script the deployment, but still...
Scott
Scott, I would highly recommend you reconsider how your application is built and rework it to enable it to handle all of these similar websites under a single web application. With a little bit of code you can easily point the controller at a different view/DB per "site" so they would each render differently but would be maintained on their own.
Chris Porter
thanks Neil. All cities are sharing the same database as well, so I really think that the multi-view solution proposed here by a few posters and yourself is the way to go.
Scott
A: 

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.

Alex Ilyin