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
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.
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.
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.
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.