Visual Studio LightSwitch 2015: Read this before you write it off

- select the contributor at the end of the page -

Rapid Application Development environments have always been the subject of debate regarding the extent of their usefulness. Microsoft LightSwitch is no exception; many folks think of it as little more than an add-on tool primarily meant for mundane tasks like early application prototyping. If you’ve been ignoring or dismissing LightSwitch as a nice toy with limited use, I strongly suggest you take a deeper look.

Why you haven’t heard much about LightSwitch

The unfortunate perception of the platform (as not being worthy of attention for serious projects) stems in part from the way it was initially marketed as a forms-generating, no-coding, power-user oriented, Access-style successor. It also hasn’t helped that Microsoft’s attention and resources have been focused on the release of .NET 2015 and Visual Studio 2015, leaving LightSwitch developers in the dark as to the tool´s roadmap and future. This worsened the uncertainty caused by the end-of-support announcement for Silverlight (the runtime that powers the original LightSwitch client) in 2021. But upon closer inspection, you’ll see that LightSwitch is an opinionated framework built on top of solid, modern, open technologies widely used in best-of-breed development projects including ASP.NET, Entity Framework, HTML5 and popular JavaScript libraries. Oh, and it likely isn't going anywhere.

Fast, fully functional and ready to use

It doesn't take much to see that LightSwitch is alive and kicking, and remains the best choice for developers looking to build real-world LOB application in half the time required with traditional tools. First off, it's fully functional and ready for use in the new Visual Studio 2015, including Community Edition, almost out-of-the box. All that’s required is to download and install the Office Tools for Visual Studio 2015 (available here), which installs the LightSwitch project templates allowing developers to create or open LightSwitch solutions.

Additionally, the LightSwitch team has put a strong focus on the HTML client since 2012. The client is very cleverly integrated into the same RAD designer experience used for the Silverlight client. The HTML applications generated, however, are modern, responsive, mobile and touch centric (they’re based on popular JavaScript libraries such as Jquery Mobile). The JavaScript infrastructure generates a JavaScript single page application with advanced features like client-side changeset management, optimized resource loading, and smart screen navigation. To put it simply, LightSwitch can now produce compelling HTML interfaces fit for consumption on mobile business devices.

What’s more, the architecture of the HTML client lets us easily extend its built-in features by taking advantage of render hooks and painlessly plugging in any external JavaScript libraries. This enables a high level of customization of the client’s look-and-feel while still leveraging the strong foundation provided by the core winjs and msls libraries and the RAD screen designers.

Powerful infrastructure

The value of LightSwitch as a LOB application builder also stems from its powerful server side infrastructure. Creating our business application’s middle tier, including data model and business rules, is a breeze using the data designers and built-in life-cycle event hooks. As we design our application’s entities using the Access-like GUI, LightSwitch generates the object model in code and creates a WCF Data Service it exposes on a public endpoint. As we add business rules, either declaratively through properties or in code through event handlers, these get automatically enforced for all data queries and updates that traverse back and forth between a client and a data source. These rules let us do things such as performing advanced custom filtering when retrieving records, or triggering specific business logic like multi-table transactional updates on data submission.

In short, just by creating some entity types and relationships, and adding some query or update rules, we immediately obtain a functional public service endpoint that can be consumed not only by a LightSwitch client, but also by any external custom client that speaks OData (including a simple browser). The service operations will enforce the entity relationships and business rules we defined on every invocation. Of course, we can also add security rules and decide who can access service operations.

We can also hook into an existing external data source, like a database, a Microsoft Azure store or some external Web service. LightSwitch will likewise generate and expose a WCF data service on top of the external source, consumable from any OData compatible client. So, with very little time and effort, we instantly generate a service layer on top of the data source, hosted in the ASP.NET application and accessible by any client we choose.

LightSwitch_01

If you’re familiar with OData, however, you may be aware that the public LightSwitch data service only allows sending complete entities back and forth between client and server. This can be limiting in certain application scenarios that require dealing with partial data types or reshaping entity data. Luckily, LightSwitch lets us easily work around this limitation through the use of WCF RIA Services; a technology that lets us connect to a data store through an in-memory custom data adapter. This way, we can fully control the shape of the data returned by our service operations using entity projections. LightSwitch then lets us plug our RIA Service into its infrastructure by again generating a WCF Data Service that exposes the custom-shaped data objects and operations of our RIA Service.

Going one step further, we may question the usefulness of our server application in scenarios involving non-OData clients. Another powerful extensibility point in LightSwitch allows us to access our server application object model from any non-LightSwitch code running in the same ASP.NET application (e.g. a web form or Web API controller). Through the ServerApplicationContext API, we can bypass the LightSwitch data service altogether and expose our object model and business rules directly, like through custom operations in a Web API controller. This means we can open our business application data and logic to the outside world as we wish. This is truly powerful, as we can enjoy the incredible speed with which we create and test our LightSwitch application’s middle-tier, and make it available to clients in any way we choose.

Takeaway

If you’ve been tempted to write off LightSwitch as a mere gadget, a Silverlight-dependent casualty of browser evolution, or just a thing of the past, think again. The platform, more than ever, stands firmly as the fastest way to build an n-tier line-of-business application using the MS stack. It lets us create responsive mobile HTML5 clients in a flash and fully customize them by writing or plugging in code. We build our server logic -- data entities, data access layer, queries, business rules – with incredible ease, before it’s automatically exposed as service operations for client consumption.

For scenarios requiring more flexibility, we can hook into external data sources, we can use built-in extensibility points to control the shape of the data exposed by the LightSwitch operations, or we can expose the data and logic through other types of endpoints. From client to server, the rapid application development promise is fulfilled, allowing us to build a complex business application in record time.

For a deep dive into the power of LightSwitch, check out Building Line-of-Business applications with Visual Studio LightSwitch 2015 on Pluralsight.

Get our content first. In your inbox.

Loading form...

If this message remains, it may be due to cookies being disabled or to an ad blocker.

Contributor

Yacine Khammal

is a senior business application consultant, and author for Pluralsight since 2010. Nowadays, his main focus is on functional, architectural and management aspects of software projects, but he likes to regularly deep dive into a new technology or framework that makes building business applications better and faster. Yacine shares his time between Morocco and Spain. You can find his blog here.