Search code examples
c#.net-assemblydatacontract

Constants, WebServices, Namespace, & Shared Assemblies


I have a large number of assemblies in my project.

  • Contract.Common; Contains all the DataContracts that are commonly used.
  • Contract.Sync; some more functionality
  • Contrct.Task; some more functionality
  • another half dozen assemblies with more functionality as the product evolved.

In general as Contract.Common was referenced by other WCF contract assemblies. Following some best practices read more WCF Architecture & Evoltion / Version, there is a static class of constants like my NamespacePrefix that I use for all contracts.

For the first time though I am developing a new Contract that is independant of the Common contracts. Let's call it Contract.NewStuff

As per norm, the new contracts reuse the namespace prefix constants in my common contracts library (which means it requires a reference to it).

For my webservice clients, I reference my contract assembly and use that to connect to the various webservices & invoke them.

Quesiton

As Contract.NewStuff only uses the common library for constants at compile time (there are no runtime assemblies), how do I stop my clients from also having to also reference my Contract.Common assembly?

I understand my Common contracts is only a 20KB assembly, and I should not worry about it. But with 300,000+ machines using Contract.NewStuff, I don't see why I should waste resources on sending that assembly, updating it in future releases etc...


Update 1

Went with the Add file as link option. No references, single place to edit the constants.


Solution

  • You can move class with constants to new assembly so Contract.Common and Contract.NewStuff will refference it. I suppose you can even "throw assembly with constants away" after compilation because constants are embeded in IL code on C# compilation time and will not be read from constants assembly each time they are needed in runtime.
    As other option is to "link" constants class to your Contract.NewStuff assembly. Inthis case you will have no file constants class duplication in both projects. Add File As Link