MonoRail (formerly called Castle on Rails), a component of the
Castle Project, is an
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
web application framework
A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build and ...
built on top of the
ASP.NET platform. Inspired by
Ruby on Rails
Ruby on Rails (simplified as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web ...
Action Pack, MonoRail differs from standard ASP.NET Web Forms development by enforcing
separation of concerns
In computer science, separation of concerns is a design principle for separating a computer program into distinct sections. Each section addresses a separate '' concern'', a set of information that affects the code of a computer program. A concern ...
using a
model–view–controller
Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of infor ...
(MVC) architecture.
The framework is commonly used in conjunction with
Castle ActiveRecord, an
ORM layer built on
NHibernate. In January 2010, version 2.0 of MonoRail was released, however, many projects use the trunk version of the source to take advantage of new features without waiting for official releases.
Although the project's name is MonoRail, it does not have any affiliation with the
Mono
Mono may refer to:
Common meanings
* Infectious mononucleosis, "the kissing disease"
* Monaural, monophonic sound reproduction, often shortened to mono
* Mono-, a numerical prefix representing anything single
Music Performers
* Mono (Japanese ...
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 i
NVelocity based on the
Apache Velocity
Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a ...
library. NVelocity is supplied with simple control blocks such as
if statements and
foreach loops. 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
The Standard Libraries is a set of libraries included in the Common Language Infrastructure (CLI) in order to encapsulate many common functions, such as file reading and writing, XML document manipulation, exception handling, application global ...
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
In computer science, separation of concerns is a design principle for separating a computer program into distinct sections. Each section addresses a separate '' concern'', a set of information that affects the code of a computer program. A concern ...
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 ViewEnginelets 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.
[Parr, Terence]
Enforcing Strict Model-View Separation in Template Engines
/ref>
Spark View Engine
is a 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
StringTemplate an
AspView
were all created by independent developers to suit their own needs.
Other view engine are:
References
Further reading
* James Avery, Jim Holmes, ''Windows developer power tools'', O'Reilly Media, 2006, , pp. 963–972 (18.6 Simplifying Web Development with Castle MonoRail)
* Steven Sanderson, ''Pro ASP.NET MVC Framework'', Apress, 2009, , p. 12 (Comparisons with MonoRail)
External links
Resources
MonoRail Documentation
Presentation on MonoRail
Blogs on MonoRail
Hamilton Verissimo's Blog
the founder of the Castle Project
Ayende Rahien's Blog (Oren Eini)
the creator of the Brail view engine
Eleutian's Blog
.net and other musings
Ken Egozi's Blog
the creator of the AspView ViewEngine
Adam Esterline's Blog
{{DEFAULTSORT:Monorail (Software)
Free computer libraries
C Sharp libraries