Distributed Enhancements coming in LightSpeed 4

One of the big enhancements coming in LightSpeed 4 is around our support for customers building distributed applications. We have implemented a number of new capabilities to help support the variety of scenarios that we have heard about from our customers over the last year.

LightSpeed 4 - data everywhere

Previously LightSpeed entities were able to be serialized and we also generated some basic DTO definitions along with mapping functions as part of the LightSpeed Designer to help provide the basics which you would need to start building applications where you want to ship your data over the wire. But we know that more applications are being built with an increasing need for either shipping entities across the wire to client applications, or for DTOs to be used across the wire and mapped back into LightSpeed entities without having to do a lot of manual work. We are also well aware that RIA Services is of great benefit to people building Silverlight applications and we wanted to add in direct support for this as well.

We will be talking in more details about these enhancements later, but let’s start by taking a look at what is new.

Annotation of DataContract attributes in designer generated code

If you take a reference against System.ServiceModel and System.Runtime.Serialization, the LightSpeed designer will now annotate your entities with [DataContract] and [DataMember] attributes which will allow the entities to be serialized correctly with WCF. This helps make the entities more suitable for use with WCF and better describes them for other Microsoft frameworks which make use of WCF to determine how an object should be serialized.

Support for distributed entities

For people building distributed applications where you need to communicate using LightSpeed entities over the wire we have now extended our support for this by adding a new DistributedUnitOfWork class which is part of the new Mindscape.LightSpeed.ServiceModel assembly. This is a direct swap in for the UnitOfWork on the client and allows you to write your code just the same as always and the framework handles communicating over the wire. On the server end, this is hosted by using the DistributedUnitOfWorkService which uses a WCF endpoint which you can configure according to your endpoint’s requirements to handle the requests.

We have designed the DistributedUnitOfWork to make all sensible UnitOfWork methods available for use including stored procedure calls and projections; however, methods which rely on direct database access such as PrepareCommand() are not supported.

Enhanced support for DTO-based solutions

Previously we provided support for DTOs in LightSpeed by way of generating some simple DTOs from the designer. These provided a basic 1:1 mapping from your entity to the DTO and came with helper functions to simplify translation backwards and forwards.

We wanted to improve on this by allowing more flexibility for customers in designing their DTOs, which often may not be of a 1:1 mapping or may only be part of a larger message. Outside of distributed scenarios, we also had a number of requests to support importing arbitrary objects into LightSpeed which could map back against an underlying entity.

So to support these cases we have added a new Import method on the UnitOfWork class which helps with all of this, and looks like this:

TEntity Import<TEntity>(object source)

When you call this, LightSpeed will use a default mapping function to check for an Id property on the source object and check to see if there is an existing entity with that Id. If there is, we will load it into the unit of work (if it isn’t already loaded of course). We will then perform a 1:1 mapping of managed fields from the source object to the entity. If the Id does not currently exist, then we will create a new entity in the unit of work and map into that instead. The entity which is imported will be returned to you, and will reflect the entity state that the object should be in (New, Default or Modified).

If you have custom mapping requirements, we’ll be providing a second overload which allows you to pass in your own custom mapping function.

For fetching objects, you can either use LINQ’s Select call for mapping, or for non-LINQ users you can use UnitOfWork.Project() or UnitOfWork.Project<T>() where T is your projected type.

Enhanced support for custom entity based services

Currently in LightSpeed you could write a WCF service with service methods taking in or returning Entity instances and they would be happily serialized over the wire. However we saw there were still plenty of questions from customers about what the best way was to implement such services and how they could use entities which were sent over the wire (e.g. is this a new entity or is it modified?).

In LightSpeed 4, in addition to the provided native annotations within the code generated by the LightSpeed designer, we have included a base class called EntityServiceBase in Mindscape.LightSpeed.ServiceModel which provides you with a recommended starting point for building your services.

This base class has the defaults we recommend for WCF already configured, and also provides an operation extension which makes available a UnitOfWork property automatically on a per session basis (by default this has been configured to be per call).

Native support for RIA Services

For .NET 4.0 users building Silverlight applications with RIA Services, we have a new assembly called Mindscape.LightSpeed.ServiceModel.DomainServices as part of LightSpeed 4.0 which will allow you to use RIA Services with LightSpeed.

Here is an example of what you would write to create a LightSpeed based DomainService:

[EnableClientAccess()] 
public class ModelDomainService : LightSpeedDomainService<ModelUnitOfWork> 
{ 
  // If we are exposing Customers through this Domain Service we would write..
 
  public IQueryable<Customer> GetCustomers() {  return UnitOfWork.Customers; } 
  public void InsertCustomers(Customer customer)  { } 
  public void UpdateCustomers(Customer customer); 
  public void DeleteCustomers(Customer customer); 
}

And in your Silverlight client everything works the same. You will have a DataSource available via RIA Services allowing you to consume the entities in exactly the same manner as with other providers.

We would especially like to thank Thomas Tucker who provided an awesome sample of using RIA Services with LightSpeed which provided the foundation of this enhancement.

We will cover off the specifics of each of these in a bit more depth in coming posts and we will be getting beta bits out to existing LightSpeed customers in the near future. Until then let us know your thoughts and feedback!

Tagged as LightSpeed

10 Responses to “Distributed Enhancements coming in LightSpeed 4”

  • You guys are killing me. I am stuck on an EF 4 project at work and you are now 8 steps ahead of EF. I can’t wait to see the new beta drops.

  • Any idea of a rough time frame for R4?

  • Superb!

    Most of the work that I do is distributed (WPF) application development with communication via WCF and it sounds like this will help simplify my development process loads.

  • Hi Carel,

    We will be starting beta drops of V4 soon, currently we are working through a documentation and sample refresh so once that is closer to completion we will be putting out more fixed dates around release.

    Jeremy

  • Hi Jeremy,

    Will PrepareCommand still work?

  • Hi Johan,

    No – PrepareCommand is not supported at the client side as it deals with database level concerns. If you were needing to do something with PrepareCommand then you could still handle this at the server by wrapping the associated logic up within a custom method call.

    Can you elaborate on the scenario a bit as it would be interesting to hear if this is something that might be worth exploring further from our end.

    Jeremy

  • Great stuff, we have been holding off moving to Lightspeed due to the complexitiesand workarounds needed in the existing support for WCF.
    This will now be a no brainer for us in moving from our shitty hibernate stack..
    Great work and we look forward to using.

    Andrei

  • […] where it needs to be with LightSpeed taking care of all the hard work. We posted about some of the highlight features for distributed solutions in an earlier blog post, but the highlights: Distributed Entities, DistributedUnitOfWork, RIA Services, DTO mapping […]

  • Do LightSpeed have support for disconnected scenarios on Windows Phone 7? I mean, is it available for SQL Lite or Effiproz databases running locally on a Windows Phone 7?

    Thank you

  • […] One of the design goals of LightSpeed 4 was that LightSpeed should be the center of your data access world. While LightSpeed is much much more than just data access, this called for looking at how we could build a Distributed Unit Of Work to help shuttle data around between rich clients, phones, internet applications and more. Distributed data is the big feature of LightSpeed 4 and the feedback we’ve received to date has been great. You can now write your client side code and have LightSpeed automatically and transparently operate over the wire as if you were working locally. You can read more about these capabilities in an earlier blog post where I hinted at what was to com… […]

  • Leave a Reply

Archives

Join our mailer

You should join our newsletter! Sent monthly:

Back to Top