Couchbase Lite 2.0 on .NET

Not available yet (still months out) but I did have a chance to do some initial work on things.  Here are some things I noticed about the process and writing things for multiple platforms with one .NET Standard DLL.

First of all, for some reason I cannot create .NET Standard DLL projects on Xamarin Studio on my Mac (although XS on my mac is being weird in general.  For example, it cannot do any Quick Fix actions) and on Visual Studio it seems that the official templates are wrong (or perhaps they are meant for the command line rather than Visual Studio itself?).  I can only seem to make a bonafide project by creating a “PCL” project and then going to the project settings and converting it to .NET Standard DLL.  So the setup of everything goes like this:

screen-shot-2017-01-17-at-7-06-03

Starting from the bottom is our new core C++ engine which allows a whole lot of code sharing which is great for our small team.  Java, Objective-C, C#, and even others in the future for ambitious community members can make use of it through its C API (one of the benefits of C is that it’s very easy to use as a shared object on many platforms).  In fact the bulk of the code will rest here (the more the better, really!)

One level up there is the LiteCore bindings.  .NET Standard 1.0 does not have P/Invoke (because Windows Phone 8 does not allow it) so it targets .NET Standard 1.1.  The bulk of this area is the C# bindings to the C API with some housekeeping to make it more .NET-like.  Thanks to .NET’s nature, though, I suppose you could use this DLL from Visual Basic .NET, F#, or any other .NET language.

A level up from that you have Couchbase.Lite, which will be the bulk of the API work.  As of this writing .NET Standard 2.0 has not been released yet, and so I’m experimenting with .NET Standard 1.4 (to enable UWP support).  Its sibling is a small support assembly which does two things.  Firstly, it provides the native C++ binary when necessary (i.e. Xamarin) and it also takes care of some things that cannot be made portable.  One example is the default directory for databases.  Right now Environment.GetFolder doesn’t seem to be a part of the .NET Standard so I have to drop down into the platform level to get a similar directory (i.e. ApplicationData.Current.LocalFolder.Path on UWP, Context.GetFilesDir on Android, etc).  Currently there are only two small implementations in this assembly.

It would be ideal to get rid of the support library, but I don’t think that can happen since there are native dependencies.  I haven’t experimented with nuget packaging yet but hopefully it will be easy to include the native dependencies on non-Xamarin platforms (or maybe even xamarin platforms as well?  I’m not sure how it all its together yet).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s