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.
-------------------------------------------------------------------------------------------------------------