A probe into the----of Castle Learning notes IOC container

Source: Internet
Author: User
Tags current time

Windsor is an IOC container for castle. It is built on top of microkernel, powerful enough to detect classes and understand what parameters are needed to use them, detect work dependencies between types and types, and provide services or mechanisms to provide alerts when errors occur.

Usually the IOC implementation steps for--> to build a container--> Add components--> Get components--> use components.

1. Building containers

Building a container is iwindsorcontainer. Then we'll register the service in the container and tell the container that the service that is registered is implemented by that class. Typically, a container can be created using the following definitions:

1IWindsorContainer container = new WindsorContainer ();

2. Add Components

Add a component to the built container and invoke the AddComponent () of the container directly to complete it. For example, now there is a write log interface ilog, the implementation of this service component is textlog, then we can add the component to the container by the following methods:

1container. AddComponent ("Txtlog", typeof (ILog), typeof (Textlog));

3. Get component

The acquisition component can be obtained directly by the key used when adding the component, and returns a IWindsorContainer, where a cast is required.

1ILog log = (ILog) container["Txtlog"];

4. Using Components

1//writes the current time to the log file

2log.   Write (DateTime.Now.ToShortDateString ()); Above is the working process of an IOC container, which uses components from creating containers--adding components--getting components. I look at a small example, that is, when I was studying the IOC combined with the resources of the internet on my own small test of the blind writing.

-------------------------------------------------------------------------------------------------------------

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.