views:

18

answers:

3

Can a windows service and a IIS site share the same dlls?

And maybe the configuration (web.config)?

A: 

Yes, basically the share the dlls that are in GAC

Flakron Bytyqi
+2  A: 

Config file, definitely not.

DLLs, certainly you can write the DLL once and have both of them call into it - I'm assuming by IIS site you mean some sort of server side code like ASP.NET - but I usually copy the DLLs into the places that each of them expect to find their dependencies rather than messing around with PATH etc.

Kate Gregory
It is possible for apps to read a remote configs file (e.g. Web App reading Windows Service config) although this is usually hideous as the 'leeching' app will need to know where the other app is installed ...
nonnb
A: 

What do you mean by share? They can certainly reference the same assemblies. If the assemblies are in the GAC it would be fine. Typically if you do not put stuff in the GAC, then the DLL's will live in the bin folders for each project. If you are not in the GAC, most often, your deployment or setup project will just lay down them in the appropriate places, even if there is more than one copy of the file. The duplication will not matter, especially since the code is the same.

You would not want to try to share the config files. The website would default to web.config and your service would default to [you service name].exe.config. Yes you could technically load the config dynamically for one or the other, but they will most likely be different. There will be all sorts of additional configuration for ASP.NET in the web.config that the service would not need.

If you did want to share some config info, I would reccommend keeping the 2 original configs, and have them reference a 3rd config that would have you common config settings. In each of the apps, you would look up this config location from their own config files, and dynamically load the 3rd one.

Mike Ohlsen