Monorail (.Net)
Encyclopedia
MonoRail a component of the Castle Project
Castle Project
The Castle Project is an open source application framework for the .NET platform.- History :The project was founded by Hamilton Verissimo de Oliveira , who was a member of the Apache Avalon and the Apache Excalibur projects...

, is an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 web application framework
Web application framework
A web application framework is a software framework that is designed to support the development of dynamic websites, web applications and web services. The framework aims to alleviate the overhead associated with common activities performed in Web development...

 built on top of the ASP.NET
ASP.NET
ASP.NET is a Web application framework developed and marketed by Microsoft to allow programmers to build dynamic Web sites, Web applications and Web services. It was first released in January 2002 with version 1.0 of the .NET Framework, and is the successor to Microsoft's Active Server Pages ...

 platform. Inspired by Ruby on Rails
Ruby on Rails
Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

 Action Pack, MonoRail differs from standard ASP.NET Web Forms development by enforcing separation of concerns
Separation of concerns
In computer science, separation of concerns is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors...

 using a model-view-controller
Model-view-controller
Model–view–controller is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" from the user interface , permitting independent development, testing and maintenance of each .Model View Controller...

 (MVC) architecture. The framework is commonly used in conjunction with Castle ActiveRecord, an ORM
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...

 layer built on NHibernate
NHibernate
- External links :*** *NuGet...

. On January 2010, version 2.0 of MonoRail was released, however, many projects use the trunk version of the source to leverage new features without waiting for official releases.

Although the project's name is MonoRail, it does not have any affiliation with the Mono
Mono (software)
Mono, pronounced , is a free and open source project led by Xamarin to create an Ecma standard compliant .NET-compatible set of tools including, among others, a C# compiler and a Common Language Runtime....

 project.

How it works

The framework maps web requests to an "action", which is a regular .NET method on the controller. The controller is responsible for invoking business services and controlling the application's flow. When it is time to send the web response to the client, the controller sets a view template to be rendered, putting data in a special dictionary object known as the "Property Bag", and delegates the template rendering to a view engine.

The view engine renders the template into the response stream utilizing the data in the property bag given by the controller. At this stage the view cannot access any other layer of the application, isolating the view from the application logic.

View engines

The mainstream view engine used in MonoRail is NVelocity, based on the Apache Velocity library. NVelocity is supplied with simple control blocks such as if statements and foreach loops
Foreach
For each is a computer language idiom for traversing items in a collection. Foreach is usually used in place of a standard for statement. Unlike other for loop constructs, however, foreach loops usually maintain no explicit counter: they essentially say "do this to everything in this set",...

. The NVelocity view templates are text files with the extension '.vm'.

Other View Engines in use:
  • Brail, based on the Boo language. Being a .NET language, the Brail view engine has stronger capabilities, as the view programmer can use the Base Class Library
    Base Class Library
    The Base Class Library is a standard library available to all languages using the .NET Framework. .NET includes the BCL in order to encapsulate a large number of common functions, such as file reading and writing, graphic rendering, database interaction, and XML document manipulation, which makes...

     methods. However, power comes with its price, as it opens the possibility to do too much in the view, leaving some responsibility for Separation of concerns
    Separation of concerns
    In computer science, separation of concerns is the process of separating a computer program into distinct features that overlap in functionality as little as possible. A concern is any piece of interest or focus in a program. Typically, concerns are synonymous with features or behaviors...

     in the hands of the programmer. The view templates are text files with the extension '.brail'.
  • AspView, a view engine that uses C# as its scripting language, and uses a pre-compiled approach, where all the views are pre-compiled to a .NET Assembly prior to deployment. The view templates are text files with the extension '.aspx'.
  • WebForms ViewEngine lets you use some of the power of Web Forms in your MonoRail applications. The use of the WebForms view engine is quite sparse, and is only recommended for a migration phase from an existing Web Forms application to a MonoRail application. The view templates are text files with the extension '.aspx'.
  • StringTemplate is the most strict view engine in terms of MVC.
  • Spark View Engine new view engine popular among ASP.NET MVC developers, supports MonoRail as well.

Other View Engines

Building other view engines is quite simple and straightforward. Brail, StringTemplate and AspView were all created by independent developers to suit their own needs.

Further reading

  • James Avery, Jim Holmes, Windows developer power tools, O'Reilly Media, 2006, ISBN 0596527543, pp. 963–972 (18.6 Simplifying Web Development with Castle MonoRail)
  • Steven Sanderson, Pro ASP.NET MVC Framework, Apress, 2009, ISBN 1430210079, p. 12 (Comparisons with MonoRail)

Resources


Blogs on MonoRail

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK