Writing Application is never the same again with LightSwitch 2011. LightSwitch is simplified and self-service model for application development. It lets the user decide whether the applications developed be deployed for Desktop or Web or Cloud.
Most of the business applications are data-centric application. Meaning, they revolve around business entities and in simpler perspective, they are either Add/Update/Delete/View of the business entities spiced with business rules, on top. That evolves the style of developing application, as well. LightSwitch is all about the smartest and easiest way of building highly robust applications, in the way we think of these business applications.
What is LightSwitch?
One line answer: LightSwitch is a new edition of Visual Studio.
LightSwitch helps developer to build application using .NET stack and wrap them into an abstraction layer which can be further optimized for maintenance and management of business entities. LightSwitch business applications are multi-tiered, featuring a client application and a combination of LINQ, WCF RIA Services and the Entity Framework to implement the application services tier. LightSwitch application is built using development best practices, on top, eliminates exhaustive and repetitive plumbing code required to construct a properly architected database, data access tier, and user interface (UI) framework.
LightSwitch comes with a unique designer and development templates. The designer include facility to design business entities, database or some form to persist these business entities (List a SharePoint), design screens to perform business action on those entities and finally, the logic and rules that bind them all together. In short, the designer with LightSwitch helps the developer with the entire ingredient required to build an application from scratch.
Where to begin the app development, did you say screen design? Let us take a step back. Typically, the screen design requirements are driven by the Data model. The Data Model is driven by the business requirement. First thing first, let us come up with Data Model and persist the data. The Data Model is presented using the entity framework 4.1.
The screen design can now be inferred from the data model or the table schema or can be built using a hybrid approach where the screens are generated and customized as per requirements. In addition to the screen design, the other part is the data rules. LightSwitch provides both declarative and imperative option. Either the rules can be defined in the property window (declarative) or written in the code (imperative), as well. They can be simple language expressions or a complete method embedded into the application using C# or VB.NET.
Let us try to create a LightSwitch Application. Before starting with a LightSwitch app development, Visual Studio LightSwitch has to be installed. For this demonstration, we had installed LightSwitch on top of Visual Studio 2010 ultimate on the machine. Hence application is built using the VS2010, as well.
Ok. Begin with a new Project. After LightSwitch is installed, on the ‘New project template’, you’ll get a new category for ‘LightSwitch Applications (Visual C#)’.
Visual Studio, as usual, does a lot of ‘behind the scene’ plumbing for the application. As mentioned earlier, the next step is to ‘Start with Data’.
Let us start with a new table. For illustration, let us build an application around an imaginative Customer who has attributes like ID, Name, DateOfBirth, etc.
With the above step, we created a business entity, named it as Customer and defined its attributes. In addition to this, the other things to do are to create Queries, add computed properties, add more entities and build relationship between them, write business rules in C# and bind them, etc. For the brevity of this demonstration, let us jump to screen design by clicking on Add Screens button on the top.
Voilà! There are so many screen templates already, by default. Do developers need to think of any other standard screens?? Well, let’s begin with ‘New Data Screen’ and then create a ‘List and Details Screen’. Note, the important aspect here is to attach the Customer entity as Business Model under Screen Data section.
Once the screen is created, the VS takes you back to the Designer page where developer can do further customization,as required. Would like to add one more screen for List and details? Let us use the Solution Explorer, right click on Screens folder and add ‘List and details’ screen. Again, remember to bind the Customer entity with the newly built CustomerListDetail screen.
To recap, so far, we’ve not written a line of code. We created an entity and two screens on top of this entity. Let us say, one for ‘New data form’ and another to ‘List and details’ screen. Can we now build the application? Do we need to do any more plumbing? May be not required! I trust LightSwitch.
Go ‘F5’ (Start debugging). The application is built and starts running.
Enter a customer detail and Save the data with save icon on the top. Then get into List view to see the other screen.
That’s it folks!! The application is ready! As required, the developer can now fit in the remaining business logics and customizations as per needs. LightSwitch makes developer’s life a lot easier.
There are many more aspects to talk about LightSwitch applications. What is covered in this write up is just an iota of the ocean. ! A lot more can happen over extensibility provisioned on LightSwitch. In addition to this simple approach of building a new application from the scratch in no-time, it also provides a customizable template that enables the developer to write custom business logic and build application that logic in no time. Also, we get tons of plug-ins and starter kit to build different kinds of applications like BI Solutions, etc. LightSwitch fundamentally enabled extension models so that the eco-system with strong developer community and independent software vendors can provide their own extensible templates and starter kits to build new applications integrated with advanced functionalities, out of box.