Getting started with Mindscape LightSpeed
11 June 2007 in .Net, Code, Mindscape, Tools | Comments enabled

Mindscape LightSpeed Logo

In the weekend I was reworking a prototype of something I’m working on and I wanted to use LightSpeed to manage the data access and thought it would be appropriate as a code example of how to quickly and easily get started with LightSpeed. To clarify, I only needed LightSpeed for the persistence mechanism as opposed to the full domain modeling capability at this stage of my project.

The Problem
My application needed a mechanism for persisting configuration. The configuration this application stores is extensible and ideally will be extended by 3rd party plug-ins which means I needed to expose a service that can be used by these 3rd parties to store their custom configuration in a manner that will give access both to their plug-in as well as our application.

I’m also a staunch hater of >300KB XML configuration files and it’s early days in the prototype :)

Step 1: Create your model classes
I have a simple configuration entity that I wanted to be able to persist to a SQLite database (LightSpeed supports many different database engines by the way). At this stage of my prototype I’m effectively only storing a key/value pair, a human readable name and description and a type (e.g. string, color, int). In this code example you will need to reference LightSpeed in your project to gain access to the Entity<> class that we are inheriting off.

Note that LightSpeed takes care of the enum as well and will happily convert it to an int at the database level :) Too easy.

using System;
using Mindscape.LightSpeed;
 
namespace Mindscape.Carbon.Core.Configuration
{
  public class ConfigurationItem: Entity<guid>
  {
    public enum ConfigValueType
    {
      STRING,
      INT,
      COLOR
    }
 
    private string _referenceName;
    private string _value;
    private ConfigValueType _valueType;
    private string _displayName;
    private string _description;
 
    public string ReferenceName
    {
      get { return _referenceName; }
      set { Set(ref _referenceName, value, "ReferenceName"); }
    }
 
    public string Value
    {
      get { return _value; }
      set { Set(ref _value, value, "Value"); }
    }
 
    public ConfigValueType ValueType
    {
      get { return _valueType; }
      set { Set(ref _valueType, value, "ValueType"); }
    }
 
    public string DisplayName
    {
      get { return _displayName; }
      set { Set(ref _displayName, value, "DisplayName"); }
    }
 
    public string Description
    {
      get { return _description; }
      set { Set(ref _description, value, "Description"); }
    }
  }
}

Step 2: Create your database
Currently you create your database manually however we are working on tools to do this for you. Note that I’m using a GUID as the primary key on this table and we didn’t need to add it to the model object in the previous step, LightSpeed does this for you. You only need to supply the primary key type in Entity. Now you can jump into whatever database you’re working with and create the table.

In my case I was using SQLite and just used a simple create table command:

CREATE TABLE ConfigurationItem(
  Id                GUID            NOT NULL PRIMARY KEY,
  ReferenceName     NVARCHAR(50)    NOT NULL UNIQUE,
  Value             NVARCHAR(100)   NOT NULL,
  ValueType         INT             NOT NULL,
  DisplayName       NVARCHAR(100)   NOT NULL,
  Description       NVARCHAR(1024)  NOT NULL);

Step 3: Add LightSpeed to your configuration
We need to tell our application about the database that LightSpeed should be working with and we can do this in code or in the .config file for our project. In this example I’ve elected to put it into the app.config of my project.

  <configSections>
    <section name="LightSpeed" 
        type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
  </configSections>
 
  <connectionStrings>
    <add name="ConfigDB" connectionString="Data Source=MyDatabase.db3"/>
  </connectionStrings>
 
  <LightSpeed dataProvider="SQLite3"
           connectionStringName="ConfigDB"
           identityMethod="Guid"/>

Step 4: Work with your data
That’s it! All the configuration work has been completed and there is no heavy XML mapping file or complex setup to tell LightSpeed about the database. The whole philosophy behind LightSpeed is to help developers get work done quickly and I hope this example and your own work with LightSpeed proves that. In following posts I will provide detail about working with your data however here is a taster of how easy it is to now put new objects into the database:

    ConfigurationItem item = new ConfigurationItem();
    item.ReferenceName = "MyRefName";
    item.ValueType = ConfigurationItem.ConfigValueType.STRING;
    item.DisplayName = "Example Config";
    item.Description = "This is an example configuration key";
    item.Value = "example";
 
    Repository.Add(item);
    Repository.CompleteUnitOfWork();

In this example I had an extremely simple model however you can appreciate that there is significantly less leg work required to get a LightSpeed solution up and running. I will post more advanced real world examples to help you gain more from working with LightSpeed in the near future. Also please leave any comments or questions you have on my blog regarding LightSpeed.

How can you use LightSpeed?
We currently are in late beta with an RTM of LightSpeed just around the corner. You can grab the download of LightSpeed from the Mindscape EAP site. You can also post in the forums to discuss any challenges that you have or to ask questions. We welcome any feedback.

Update: LightSpeed was released and is now available to play with here: http://www.mindscape.co.nz/products/LightSpeed/

Hope that helps,

– JD


2 comments. Add your own comment.

John Rusk says 8 July 2007 @ 23:26

Nice example JD.

Is there any issue with using the “Set” method from VB.NET? (I’m assuming that VB.NET is a reserved word in VB.NET).

By the way, you might be interested in this code that I just posted here: http://dotnet.agilekiwi.com/blog/2007/07/claytons-interception.html Hope you don’t mind me using LightSpeed as the example.

traskjd says 9 July 2007 @ 09:26

Hi John,

There isn’t any issue as long as you change from a raw Set() to Me.Set().

Thanks for the post, it’s great to see you using LightSpeed in your example.

Hope that helps,

– JD

Leave a Comment

Name (required)

E-mail (required - not published)

Website

Your comment: