How do you organize your projects/solutions for reusablity?

NetMF has assemblies for the framework code (and GHI extensions). It also has namespaces to allow keeping collisions to a minimum. I have (over the last few years) developed some potentially reusable components. I use Interfaces to draw a clear line across the responsibilities of each component and that has worked well. The problem with including assemblies is keeping track of which version I have included with a particular program and the pain that occurs when the NetMF version changes. I learned about the technique of including a project from a different folder/solution and that seems to work pretty well during the debugging phase (which seems to never end, since NetMF keeps moving). To put this into a concrete example, I have a component that displays text (ITextDisplay). It has a very simple interface that I can use from other components. It originated from something for the Nokia5110 display and I generalized it years ago and adapted it to work with the display on the CANXtra and then the N18. Since it appears that Gadgeteer is on the way out, I have been reworking it to work without that requirement and work with generic SPI displays based on the ILI controller. So, I now have:

public interface ITextDisplay
public interface IBitmapDisplay
public class TextBitmapDisplay : ITextDisplay
public class IliBitmapDisplay : IBitmapDisplay
static IliBitmapDisplay Display = new IliBitmapDisplay(isLandscape: false,
                                 lcdChipSelectPin: GHI.Pins.FEZCobraII.Socket6.Pin6,
                                 dataCommandPin: GHI.Pins.FEZCobraII.Socket6.Pin5,
                                 resetPin: GHI.Pins.FEZCobraII.Socket6.Pin3,
                                 backlightPin: GHI.Pins.FEZCobraII.Socket6.Pin4,
                                 spiModule: GHI.Pins.FEZCobraII.Socket6.SpiModule,
                                 width: 128, height: 160);
static TextBitmapDisplay TextDisplay = new TextBitmapDisplay(Display, SmallFont, BigFont);

TextDisplay.Print("Qylpe 10°F   " + System.DateTime.Now.ToString("HH:mm:ss"), Colors.Red);


How would you structure the projects/solutions and why?

Right now, I have 5 projects (which seems a bit excessive, but does work). Since ITextDisplay and IBitmapDisplay are somewhat related, they could and probably should be in the same project/folder/solution. The two implementations are related in that one needs to use the other, so they probably could be separate, but from wanting to minimize the number of assemblies putting them together might make sense. The 5th project is the example program that demonstrates how everything works.

My current practice is to make liberal use of shared-source projects. Put the source for a given library in a single shared-source lib, and then build 4.3, 4.4, Mono and .Net platform-specific versions using the same shared-source lib. Platform-specific stuff goes in the platform-specific projects and I use an interface and statics or dependency-inversion to locate those platform specific bits.

Generally, using assemblies for modularization is a good plan, but not so much in NetMF because there is a memory cost to each assy, so shared-source libs can help there too.

For reusable components, I use two nuget repositories - my open source stuff goes in nuget.org, and my private stuff goes on a private nuget share. I use nuget because it take care of that versioning problem for you. You don’t have to update all your projects, just because you updated a heavily used library.

3 Likes

I currently use a custom database to manage my code reusability, every piece of code that i think may someday be usefull goes in there. it is ordered by programming language and functionality