As we work on CSLA Light (CSLA .NET for Silverlight), there's (at least) one continuing point of debate in the team - so I thought I'd gather more input.
One goal of CSLA Light is to allow the majority of your business code to be the same in Silverlight and .NET. The data portal runs between the two platforms, and your business objects literally move from .NET to Silverlight and back again. Very cool stuff!
This means that the same physical class file is included in two projects - a Silverlight Class Library and a .NET Class Library. We do this using the ability in VS to "Link" a file from one project into another, so the file exists once, but is in two projects. Pretty easy once you do it.
That all works nicely - for code that is 100% compatible with CSLA Light and CSLA .NET. This includes your property declarations, validation rules (mostly) and authorization rules.
This does not include your factory methods (usually) or your data access code. Silverlight doesn't even have the data access technologies available on .NET, so that code simply can't compile or work in Silverlight.
What this means is that, for a given business object like CustomerEdit, you could have three types of code:
- Shared code that runs in Silverlight and .NET
- Code that only runs in Silverlight (rare but possible)
- Code that only runs in .NET (data access at least)
So that linked class file will at least contain the shared code.
Using compiler directives like "#if SILVERLIGHT" and "#if !SILVERLIGHT" the linked class could contain all three types of code. It is just that some of it won't compile on Silverlight or .NET obviously.
Another solution is to use partial classes. In this case there'd literally be three different files. The linked one with the shared code, a partial class in the Silverlight Class Library for the SL-only code, and a partial class in the .NET Class Library for the .NET-only code.
Either solution gets the same end result - all three types of code are there. The compiled results are the same either way.
We're really just talking about coding style - which is easier to understand, read, and explain?
Would you prefer to see all your code in one file, with sections blocked out with #if statements?
Or would you prefer to split your code into three files, each one with clear meaning?
(please note that CSLA Light will support either model - but all our examples, etc will be in one mode or the other - we're just trying to figure out what to "recommend" as the best approach)
Your input is very welcome!!
Rocky