Translate

Wednesday, June 8, 2011

Getting started with MonoCross

What is MonoCross?

MonoCross is a C# .NET Model-View-Controller (MVC) framework where the Model and Controller are shared across platforms and the View is implemented for every specific platform and/or target architecture. It allows the development of both native and HTML5 web apps that share business logic and data code.

MonoCross is based on a modified Model-View-Controller pattern that enables separation of the presentation layer, (View) from the application code (Model + Controller). This modification enables portability of application code across multiple platform targets.
Source code and solution files for the MonoCross pattern, and the Best Sellers sample. Includes container projects for Windows Console, Mobile WebKit, iOS*, and Android^
*iOS projects require MonoTouch and MonoDevelop, all other platforms can be developed in Microsoft Visual Studio.
^Android projects require Mono for Android and Visual Studio Professional 2010.

Although MonoTouch and MonoDroid use the same language and development environment, they still require knowledge of the native coding conventions when building a presentation layer. MonoTouch uses the same native concepts that are used in CocoaTouch, (View Controllers and Delegates), and MonoDroid uses the same Activity based model used in native Android Java.

Container:
In order to run the shared application, you must create at least one container project that references the appropriate shared assembly, and renders the application into the targeted presentation platform. The BestSellers application is initially published with three platform containers:
• Console.Container - A Windows Console based deployment; this is the simplest example and is a good place to start in understanding the pattern.
• WebKit.Container - An HTML 5 deployment using ASP.NET and WebKit to render to small form-factor mobile devices, (iPhone, iPod, Android, etc.).
• Touch.Container - A native iOS deployment using MonoTouch.

Controller:
MonoCross controllers will be derived from the abstract MXController class. This class defines the base functionality necessary to register your controllers in your MonoCross application, and initialize your model objects for delivery to your container(s). You'll accomplish this by overriding the MXController.Load() method.

Model:
Design your model in a way that delivers only the information your audience needs at the time they need it. Less is definitely more when it comes to mobile application design. Take an "outside-in" view of your information with the device or devices you intend to support in mind.

View:
When constructing your views, MonoCross lets you take full advantage of the capabilities of your native platform. So construct your views in a manner that will present your information in a manner optimized for your deployment. MonoCross views inherit from the MXView class. The view Render() method must be overridden to implement any actions necessary to initialize and present your model information to the target platform.

Application:
Now that you have defined your model and your controllers you need to register your controllers in your shared application. The MXApplication class is an abstract super-type that contains the constructs needed to define your workflow, and register your controllers for use in your container.
To initialize your shared application you need to override the OnAppLoad() method of the abstract base-class. This method is called when your application is initialized, and contains the code necessary to establish your app structure.

Navigation:
The NavigationMap property is a collection of all the controllers necessary to render your application to your desired platform target(s). The NavigationMap is keyed using a URI template model which defines your application workflow. Each user-action will initiate a navigation based on the URI patterns defined in your NavigationMap.
This navigation paradigm is key to the MonoCross pattern, and enables tremendous flexibility in construction of your application. Controller-View combinations can be re-used at different points in your workflow by simply defining multiple endpoints in your NavigationMap with unique URI definitions.

Binding your App to the Container:
Now that your views are defined, all that remains is to initialize your application and bind it to your container. there are three steps to the process that must be completed in the Main() method, or equivalent entry point to your platform-specific container application
• App Initialization - set the view load event delegate, and initialize the MXContainer with an instance of your app.
• View Registration - register your views with your container using the MXContainer.AddView() method.
• Initial Navigation - perform an MXContainer.Navigate() navigation to the initial view of your application.

I have tried to define each component which is part of MonoCross framework. I collected above information from various sites mentioned below in resources section. MonoCross example is explained well in WIKI article UsingMonoCross link: http://code.google.com/p/monocross/wiki/UsingMonoCross

Resources:
MonoCross Home page: http://www.mobileframework.net/
MonoCross Download: http://monocross.net/
UsingMonoCross WIKI article: http://code.google.com/p/monocross/wiki/UsingMonoCross
MonoCross basic overview: http://vagabondrev.org/2011/04/20/monocross-the-technology/

1 comment:

  1. Here is a database compatible with MonoDroid:
    http://www.kellermansoftware.com/p-43-ninja-net-database-pro.aspx

    ReplyDelete