Castle-startable facility

Source: Internet
Author: User

I recently studied the castle open-source project and learned some simple understanding of startable facility in the afternoon,
Because Castle has a relatively small amount of learning materials and most of them are in English, some Chinese materials are self-learning,
Therefore, I hope to learn about him in a simple and easy-to-understand way, so there will inevitably be some incomplete points.
Facility is an extension unit of the castle container and is injection-oriented. Simply put, you need to inject the required functions without changing the original components.Code,
Facility is equivalent to the "Parasite" of the original component. The startable facility introduced in this article is a very simple facility built by Castle,
This facility can automatically execute code when the original component is created and destroyed.
First, we need to establish this "Parasite" class teststart, which inherits istartable and defines the start and stop methods.

Public class teststart: istartable
{
Public teststart ()
{
 
}
Public void start ()
{
MessageBox. Show ("testetsete ");
}

Public void stop ()
{
... Omitted
}
}

Then, load the "Parasite" into the container
Public class app
{
[Stathread]
Public static void main ()
{
Iwindsorcontainer Container = new windsorcontainer ();

Container. addfacility ("startable", new startablefacility ());

Container. addcomponent ("test", typeof (teststart ));
}
}
In this way, a window will pop up when you are running, and the START () method of teststart will be executed.

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.