Wednesday, April 17, 2013

Imagine that we have already build a mobile app using DXTREME such as the DXSK8 demo and already have a ready-to-use Entity Framework data model. Now we are faced with a task to provide a rich administrative application that will be mainly used in Intranet from the desktop (Windows) or web browser. This application should have a typical CRUD UI for managing goods in an online shop, content on our main web site, etc. and of course have potential for future extensibility and customization by a customer request. Following the instructions of this post it should be easy to do it your self from scratch in less than five minutes! (Sample app at then end of this post).

Below we see the created solution which contains two ready to run XAF applications (DXSK8.Admin.Win, DXSK8.Admin.Web) and three empty XAF modules where the DXSK8.Admin.Module is the platform agnostic one. We are going to work in the platform agnostic module because we want to minimize code duplication between our Win and Web XAF applications.

2) Adding Entity Framework model types to XAF

XAF auto generates rich CRUD UI for our data using our award-winning DevExpress visual components. However our Entity Framework model is located in an external library so in our platform agnostic module we need to reference the EF model container which is the DXSK8.Service assembly along with the System.Data.Entity and DevExpress.ExpressApp.EF assemblies.

Next its time to add the all the EF model entities in our application business model by using the following code in the constructor of this platform agnostic module.

3) Switch the Application to Using the Entity Framework

We continue to work in the platform agnostic DXSK8.Admin.Module. To use the EFObjectSpace instances to access data we need to provide an IObjectSpaceProvider implementation designed for EF and located in DevExpress.ExpressApp.EF assembly. For this we need to modify again our Module.cs codebehind class as shown.

Note that EFObjectSpaceProvider’s first parameter is Entity Framework’s ObjectContext implementation from DXSK8.Service project.

Conclusion

Microsoft recommends when accessing data to use Entity Framework, which from v5 is open sourced and has an unlimited list of add-ons and really big audience. We used this amazing technology to create the DXSK8 data service and in this post we demoed how to use XAF with three simple steps to manage its content by creating rich CRUD UI views as below on the spot. Therefore it should be clear that we can deliver app prototypes for our EF models really fast and our end users can enjoy access to their data with modern UI look & feel from day one! Note that XAF has a lot of build-in and open sourced modules that can be install with a simple drag and drop and can save you months of work.

In the next images we see two of the default auto generated XAF CRUD Views one for each platform (Win and Web).

For those of you that you have Entity Framework models and you want to try these instructions on them you may download an XAF trial from here.

Monday, April 15, 2013

Recently we made the decision to clone our Winforms VideoRent real world application and create a new XAF application – the XVideoRental. Wearing my LEGO designer hat I will go through all migration steps as if I were in your shoes.

XVideoRental uses only a small part of XAF tooling –>Native modules + Code Central examples + open sourced project and community resources. All the time invested was for gathering ready to use implementations and putting them in a reusable project agnostic library. In addition since all these ready to use implementations exist already in our community project (eXpand) we created a second open source version of XVideoRental where this project agnostic library does not exist so we consumed even less resources for building it!

As you can read in the overview post the XVideoRental contains almost zero designed time code and everything is described declaratively in XAF’s Application Model xafml file, allowing full customization after distribution.

Real world applications are really demanding. We spend huge times for first release and in most cases is very poor compared to the next ones. The reason is simple, we do not have enough time to prepare a domain-specific language (DSL) that will bridge business requirements with our existing technical tooling/knowledge. Therefore we try to re-invent the wheel in many areas whereas XAF exists as the most comprehensive tooling available. Using application model and the Security System, XAF fully describes and configures the behavior of platform agnostic applications. Both Application Model and Security System are the technology abstraction or in other words the DSL language we need to minimize the time to market cost of a real world application.

We recommend:

1. Watch the BUILDING A PROJECT MANAGER APPPLICATION IN 5 MIN video where we used the same LEGO designer approach as in XVideoRental in a simpler application as our MainDemo.

In short the legacy app is using 256 classes. The XVideoRental much less 77 and 90% or them are simply concrete implementations from the referenced project agnostic library. However in the 3rd row where this project agnostic library is replaced from a reference to our open source project that number of classes goes further down to only 36!

4. Finally go through the list bellow where we compare the legacy and XAF application side by side.

Legacy VideoRent

XAF XVideoRental

Data Access

• Legacy app uses ORM technology and our XPO to describe the video rent business. However special skills needed and extra efforts to create a clear separation from other layers, so many helper classes exists even for very common tasks such as database connectivity.

• XAF has built-in support for both XPO and MS Entity Framework. We can simply utilize the legacy domain model by simply copy- paste the classes. Helper classes are of no use because XAF can handle all common tasks transparently for us!

• A real world application requires an importing mechanism for initial data. The legacy app imports data from xml files with structure that fits exactly to the structure of the business objects. Therefore even for a small change in the BO design we need to modify and retest this mechanism.

• In a real world application sequential number integration is essential. However special design and knowledge is needed to be able to build something reliable.

• XVideoRental operates under a business application framework therefore a rich click and run SDK provides solutions to such common problems E2829. So the developer only needs to integrate and not to think about the technical difficulties or guess the showstoppers.

Architecture

Legacy app has a design time modularization based on Forms/UserControls/(Bussiness Concept). However it is not possible to extended it without adding new Forms and recompiling the whole application inside VS. In addition because of the lack in documentation determining the best place to write code for a specific behavior can still cause big headaches.

Application life cycle is component centric and was invented on demand for the current application.

XVideoRental demo is using XAF’s well-documented and simple to use MVC architecture. Also, while the discussed application is a simple fat client app, demanding users looking for something more advanced may also find a ready to use client-server solutions in XAF.

• VS templates to fast create modules. which by design are reusable and independent from main application. • Well documentedApplication life cycle guide us where we to write code (e.g. Setup, Login, View Activation etc.) • Simple to follow tutorial on how to Extend Functionality. • Detailed guide of all the main concepts for building business applications.

Data Validation

A real world application without strong validation support is unstable and has huge support times. Building a validation engine is not trivial at all and requires third party components which will raise the cost even further. Therefore the legacy application time frame and budget wouldn’t allow any investment here and there is no validation support.

Creating validation rules does not require you to be a developer, even end-users can create them because it is quite easy and intuitive, not more difficult than creating a filtering rule in your Outlook. We only need to install the build-inValidation module!

Data Representation

The legacy application a large number of components. Therefore the developer requires A huge amount of mundane, repetitive work was invested to:

XAF has native support for a large number of DX components. Automatic UI generation (CRUD detail and list forms, navigation and menu systems - all based on data models). This is a huge time saver because almost every typical business application contains a good percentage of list and detail forms, navigation and menu systems - all linked together without any effort from your side.

• Create a large number of data entry forms, drag & drop numerous controls on it, arrange their positions and configure data bindings • Providing a consistent look and feel is not an easy job and requires deep knowledge of a large number of components as well as a special design • Interact with the database through XPO, create CRUD operations and support transactions needs careful considerations and a lot of time, so it was done as basic as possible by simply pushing non mandatory tasks such as undo operations and transaction for the next application release . • In an agile real world the navigation menu system should be controlled as declaratively as possible. However legacy app does not conform this requirement resulting in huge update times for every customer request. • Extend XtraReports for every Business object we want to create reports. • Design reports inside VS making their support impossible in real world. • Design analysis views inside VS making their support impossible in real world.

Although most of the components can persist their state there is no application level integration by default. In addition their serialization is not designed to be human friendly and its hard to edit and support. The legacy developer had to create an integration mechanism deep in application’s infrastructure. This costly. wrap-up was as basic as possible and target only a few major forms producing a non consistent feeling.

XVideoRental is a XAF application which by design is described declaratively in XAF’s Application Model. Using Model Editor at runtime an end user can modify any part of the app.

However we didn’t spend the 10 min required to plugin the ModelDifference community module and consume the application from a persistence storage such as a database cause we were building a clone and not demo the endless features of XAF!

Zero migration resources for this one!

Application Security

The legacy developer tried to create a basic security implementation. However he soon realized that the efforts needed for something useful and reliable will probably exist the efforts for building the whole application. So, unfortunately due to app budget there is no investment in implementing a security system.

The major goal of business applications is to be able to create and print reports.

Therefore the legacy app has a dedicated project for reporting. In which the developer had to use Visual Studio for report design. As a result he loosed any chance to update them on demand after project distribution which is a really common case.

At the same time the reports were extended and bound to VideoRent business objects making the whole implementation not reusable from any other project.

Moreover we provided collaboration/filtering with other views using as usual a no code approach as discussed in Visiting dashboards.

Data Printing and Export

The legacy developer had to write special code for each control on your forms that he wished to print or export. Although this functionality is very useful in real world again the time frame wouldn’t allow such an investment.

You probably can guess why eh? As usual XAF has a built-in generic mechanism for all controls out of the box!

Data Analysis

Legacy app has a whole structure to support only a few data analysis views for the 4 major BO which are Customer, Movie, Receipt and Rent. Huge amount of code is located in dedicated forms for each analysis views making the solution not able to survive in real world. The reason of course is that for each new customer request the developer has to change the code inside VS recompile and redistribute the app. A common example is a calculated value where it needs a UI to define these members, special algorithms to create them

There are technics for localizing .NET application via satellite assemblies however they do not localize application specific data and they are very time consuming, so the legacy app does not support any kind of localization

XAF supports all standard localization approaches and also addresses the problems that occur with them. With XAF, it is always possible to localizeany part of your application at runtime (e.g., correct certain values from satellite assemblies). A convenient wizard provides the capability to use online translation services from MS, Google, etc. So, it is possible to leave the localization job to non-programmers who can easily import/export data without leaving the application.

Customizing Controls Appearance

Even for the simplest operation like making bold a grid column or hiding a control from a view developer time is needed as long as recompilation and redistribution of the application

This is control-agnostic and we spared our time digging into the specifics of each control – XAF did everything for us!

Implementing Custom Business Requirements

Lets talk a concrete example here. The legacy app uses tooltips to create a more expressive UI. However even if the developer wrote a decoupled class at the end he has to attach it to various controls and forms. This makes the whole design not flexible since changes require developer presence.

XVideoRental can use the same decoupled class from the legacy application. However it simply attaches the behavior to application model instead of attaching it to controls and forms. This solution is project agnostic and allows later changesfrom a nonprogrammer at runtime! This process is discussed in details in Tooltips to the max - expressive UI.

Getting Help and Support

Application and developer are simply married. If for any reason they divorced then everything becomes very unstable and tricky. It is really hard to find another developer to continue support a legacy app. Even if we manage to do so the cost will be extremely high since there are no docs, support etc.

XVideoRental uses bricks/samples from XAF’s code central and community project. Thus by design there is a large number of developers that can support its code base. Not to forget the unmatched documentation and support we can get from the XAF team.

Conclusion

Even thought XAF does not contain solutions to each and every business problem in the world, the framework is very strong in providing its own extensibility ( "preventing the lock-in effect"). It is fast and easy to plugin solutions to common business problems, at the end XAF is a Domain Specific Language that that can bridge business requirements with our existing technical tooling/knowledge!

Welcome to my Blog

My name is Apostolis Bekiaris and I am working for DevExpress as a technical evangelist for the frameworks team, .Net is my passion and at this blog you will find a lot of my work using DevExpress Xaf framework and many others. If you want to contact me you can use the link bellow