Windsor Introductory Tutorial---The third part of writing the first installer

Source: Internet
Author: User

Brief introduction

In the second part we created the Controller factory. Now we have to give our controller to Windsor to manage.

Installer

Windsor has a dedicated class Installer.cs that is used to register components with the container. There will be at least a few of these installer classes in your application, so keep their code neat and visible. Next, create a new dedicated folder "Installer" in our application to hold these classes. The first thing we want to register in the container is the controller, so let's start with a new ControllersInstaller.cs class.

Controller Installer

The installer class needs to solve two problems for Windsor: How to find the controller in the application and how to configure the controller.

1th, how to find the controller? Very simply, in ASP. NET MVC, the controller is to implement the IController interface.

Configuration is simple, first of all, the MVC framework requires that we create a new controller instance for each request. The Windsor default is to create instances only when the first request is made. The corresponding installer class:

This class overrides the Iwindsorinstaller install method and registers the controller with the Windsor Fluent registration API. This is the most concise and flexible method we recommend. Whenever we add a controller to the application (there may be hundreds of of them in a large application), Windsor automatically registers them, and we don't need to do anything manually, we just follow the Windsor convention.

To continue looking at the code, the static class classes is the entry point for registration, first calling the non-abstract method of the public type fromthisassembly (), which is a component that contains the Registrar (MVC component, which exists in the controller's life cycle). But we do not need to register all the components, so the basedon<icontorller> filter requires that the class must implement the IController interface, although called BasedOn, but it is also a generic interface. The last is a very important point----instance Lifestyle.mvc want to use after the destruction, but each time Windsor need to have a new instance, and notify Windsor when the instance is not required, you can reclaim the instance is the role of the caller (this is why we are in the WindsorControllerFactory The Releasecontroller method is overridden in the class).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.