During the translation process, many codes provided on the official website are incorrect. I will give comments in the article or directly change them to the correct one. Therefore, the content is different from the original one. I hope you can understand it.
We recommend that you use the following project structure as a general convention:
The following sections will show you how to create this structure manually or using the monorail Project Wizard
Use monorail Project Wizard
If you have installed the castle project using the MSI installer, you may have installed the visval studio integrated environment. If so, use the Wizard to create a new monorail project.
Note:
Visual Studio 2005 users must download and install Web project support for Visual Studio; otherwise, the wizard will not work.
Open Visual Studio and run the new project. Select the castle monorail project:
InputGettingstartedsampleAs the project name
Start the wizard, select the nvelocity view engine, and clickNext
Check the options for creating a test project and clickFinish. This wizard will create a solution and project file for you and configure all the information. This may take some time.
Now you should have a project ready to run
Continue with your first controller and view.
Create a project manually in Visual Studio
If you have not installed the vs integration environment or do not want to use the Project Wizard, You can manually create a project structure.
CreateASP. NET Project(If your Visual Studio Is Not InstalledASP. NET ProjectSupport program, you can choose to createClass Library Project).
Add and reference the following Assembly:
- Castle. Monorail. Framework. dll: the monorail framework
- Castle. Monorail. Framework. Views. nvelocity. dll: The view engine we are going to use
- Castle. components. validator. dll: Our lightweight validation infrastructure
- Castle. components. Binder. dll: The binder implementation
- Castle. components. Common. emailsender. dll: the email service contracts
- Castle. components. Common. emailsender. smtpemailsender. dll: the email service implementation
- Castle. Core. dll: core functionalities shared by projects
- Nvelocity. dll: The template engine
Create the following folders in the project. Once again, this is just a conventional Convention. We suggest you follow it. However, after you are familiar with the framework, you can create a structure that is more suitable for your project.
Final ConfigurationWeb. configFile. You must register the HTTP handler, HTTP module, and monorail configuration nodes:
Add a monorail configuration node:
<Configuration>
<Configsections>
<Section
Name = "monorail"
Type = "Castle. Monorail. Framework. configuration. monorailsectionhandler,
Castle. Monorail. Framework "/>
</Configsections>
<Monorail>
<Controllers>
<Assembly> gettingstartedsample </Assembly>
</Controllers>
<Viewengine viewpathroot = "views">
<Add type = "Castle. Monorail. Framework. Views. nvelocity. nvelocityviewengine,
Castle. Monorail. Framework. Views. nvelocity "/>
</Viewengine>
</Monorail>
Note: The above is the configuration on the official website. In fact, this is not working properly. You need to add an attribute to viewengine to change it to this.
<Viewengine
Viewpathroot = "views"
Customengine = "Castle. Monorail. Framework. Views. nvelocity. nvelocityviewengine,
Castle. Monorail. Framework. Views. nvelocity "/>
To be able to use imagesCastleOrRailsFor such an extension, you also need to register the HTTP handler:
<System. Web>
<Httphandlers>
<Add
Verb = "*"
Path = "*. Castle"
Type = "Castle. Monorail. Framework. monorailhttphandlerfactory,
Castle. Monorail. Framework "/>
</Httphandlers>
</System. Web>
</Configuration>
Finally, register the HTTP module:
<System. Web>
<Httphandlers>
<Add
Verb = "*"
Path = "*. Castle"
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>
Continue with your first controller and view.