2

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.

Community
  • 1
  • 1
M Afifi
  • 4,645
  • 2
  • 28
  • 48

1 Answers1

0

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

Community
  • 1
  • 1
petro.sidlovskyy
  • 5,075
  • 1
  • 25
  • 29
  • I guess that's the question. How do I throw away the assembly with constants away? – M Afifi Aug 30 '12 at 11:02
  • 1
    Please take a look on this article http://www.codeproject.com/Articles/74671/One-reason-to-prefer-readonly-to-const-in-C and here is part of MSDN http://msdn.microsoft.com/en-us/library/ms173119.aspx "when the compiler encounters a constant identifier in C# source code (for example, months), it substitutes the literal value directly into the intermediate language (IL) code that it produces. Because there is no variable address associated with a constant at run time". That means that constants are embeded directly in IL code as is and there is no call to any filed to get const value. – petro.sidlovskyy Aug 30 '12 at 11:08
  • The add file as link option is interesting, though I suspect Reflector will throw a fit about Namespaces etc... – M Afifi Aug 30 '12 at 11:09
  • I suggest you use `readonly` instead of `const`. Also see http://stackoverflow.com/questions/4485682/c-what-does-compile-time-const-mean – Developer Aug 30 '12 at 11:39
  • @Lakeland-FL that's exactly what I wanted to avoid (runtime dependencies) – M Afifi Aug 30 '12 at 12:50