Table of contents
- 1 The minimal configuration
- 2 The formal definition
- 2.1 The monorail node
- 2.2 The controllers node
- 2.3 The viewcomponents node
- 2.4 The viewEngine node
- 2.5 The services node
- 2.6 The extensions node
- 2.7 The routing node
MonoRail Configuration Reference
MonoRail requires a small configuration on your web.config. This document should help you to understand the whole configuration schema in details.
The minimal configuration
The following is a standard minimal configuration required to get MonoRail working with all defaults. Unfortunatelly the project assembly name must be informed (we cannot infer it).
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="monorail" type="Castle.MonoRail.Framework.Configuration.MonoRailSectionHandler, Castle.MonoRail.Framework" /> </configSections> <monorail> <controllers> <assembly>ProjectAssembly</assembly> </controllers> </monorail> <system.web> <httpHandlers> <add verb="*" path="*.rails" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" /> </httpHandlers> <httpModules> <add name="monorail" type="Castle.MonoRail.Framework.EngineContextModule, Castle.MonoRail.Framework" /> </httpModules> </system.web> </configuration>
This configuration defaults to use the WebForms view engine and uses the ProjectAssembly as the source of controllers and ViewComponents.
The section monorail must be declared on the configSections.
The formal definition
The following exposes all available nodes. It can be used to extend and change the default MonoRail behavior by supplying custom implementation of services.
<monorail useWindsorIntegration="true|false" checkClientIsConnected="true|false" smtpHost="" smtpPort="" smtpUsername="" smtpPassword="" > <!-- Custom Factories should be configured on the services node. The following is supported to be backward compatible --> <customControllerFactory type="type name that implements IControllerFactory" /> <customComponentFactory type="type name that implements IComponentFactory" /> <customFilterFactory type="type name that implements IFilterFactory" /> <controllers> <assembly>AssemblyName1</assembly> <assembly>AssemblyName2</assembly> </controllers> <viewcomponents> <assembly>AssemblyName1</assembly> <assembly>AssemblyName2</assembly> </viewcomponents> <viewEngine viewPathRoot="views" customEngine="ViewEngine.Type.Name, Assembly"> <additionalSources> <assembly name="" namespace="" /> <assembly name="" namespace="" /> </additionalSources> </viewEngine> <!-- List of services ids: Custom ControllerFactory ViewEngine ViewSourceLoader ViewComponentFactory FilterFactory ResourceFactory EmailSender ControllerDescriptorProvider ResourceDescriptorProvider RescueDescriptorProvider LayoutDescriptorProvider HelperDescriptorProvider FilterDescriptorProvider EmailTemplateService ControllerTree CacheProvider ScaffoldingSupport ExecutorFactory TransformFilterDescriptorProvider TransformationFilterFactory ViewEngineManager UrlBuilder UrlTokenizer ServerUtility ValidatorRegistry AjaxProxyGenerator --> <services> <service id="[see list above]" type="Service.Type.Name, Assembly" interface="optional" /> </services> <extensions> <extension type="Extension.Type.Name, Assembly" /> <extension type="Extension.Type.Name, Assembly" /> </extensions> <routing> <rule> <pattern>(/blog/posts/)(\d+)/(\d+)/(.)*$</pattern> <replace><![CDATA[ /blog/view.rails?year=$2&month=$3 ]]></replace> </rule> <rule> <pattern>(/news/)(\d+)/(\d+)/(.)*$</pattern> <replace><![CDATA[ /news/view.rails?year=$2&month=$3 ]]></replace> </rule> </routing> </monorail>
The monorail node
| Attribute | Description |
|---|---|
| useWindsorIntegration | Enables Windsor Container integration |
| checkClientIsConnected | Enables checks for client connection that stops the process if the client has disconnected |
| smtpHost | The smtp host, if there is intention to use MonoRail e-mail features |
| smtpPort | The smtp port, if it is not using the default port |
| smtpUsername | The smtp username (if it requires authentication) |
| smtpPassword | The password (if it requires authentication) |
The controllers node
The controller node takes one or more assembly nodes. The assembly names are used during initialization as MonoRail will inspect them for controllers to construct a tree.
This node is only used by the default controller factory. It may be ignored by different factories. For example, if Windsor Container integration is enabled, the node will be ignored.
The viewcomponents node
The viewcomponents node takes one or more assembly nodes. The assembly names are used during initialization as MonoRail will inspect them for ViewComponents to initialize a dictionary.
This node is only used by the default controller factory. It may be ignored by different factories. For example, if Windsor Container integration is enabled, the node will be ignored.
The viewEngine node
The viewEngine node informs MonoRail of the views folder (which may be a relative or an absolute path) and allows the programmer to specify a custom implementation of IViewEngine.
| Attribute | Description |
|---|---|
| viewPathRoot | The folder that contains the views |
| customEngine | Full .net type name of a type that implements IViewEngine |
The additionalSources node
Some view engines implementation allow you to use assemblies resources to store views, beside the file system. This is a good approach to reuse controllers among projects.
| Attribute | Description |
|---|---|
| name | The assembly name (without extension) |
| namespace | Resources can have a namespace in their names. The namespace must be informed so it can be stripped to allow MonoRail to find the view content as it was in the file system. |
The services node
MonoRail is composed of a few services. They can be replaced by custom implementations.
| Attribute | Description |
|---|---|
| id | The service id used internally by MonoRail |
| type | The implementation type name |
| interface | If the service is defined by an interface contract, it should be specified on this attribute. |
The extensions node
Extensions can be added. They hook some events exposed by MonoRail to act on them augmenting its functionality.
An extension must implement the IMonoRailExtension interface.
The routing node
Routes can be added to define rewrite rules for the urls. This allow nicer urls but can only be used under some conditions.