Batchregistration facility is an expansion unit that assists with Castle IOC container configuration. We can easily load component and facility in the container. You can compile a separate component or facility into a DLL, and then use the configuration file batchregiility facility" One-time "Or" Filter "And then added to the container without the need to hard code addcomponent and addfacility, the flexibility is very high ~
1) load all components in the Assembly that define Castle. model. castlecomponentattribute.
< Facility ID = "Batchregistration" >
< Assemblybatch Name = "Myassembly" Useattributes = "True" />
</ Facility >
2) It will not be loaded except component1. Other castlecomponentattribute definitions will be loaded.
<FacilityID= "Batchregistration">
< Assemblybatch Name = "Myassembly" Useattributes = "True" >
< Exclude Type = "Myassembly. component1" />
</ Assemblybatch >
</Facility>
3) load only component2
< Facility ID = "Batchregistration" >
< Assemblybatch Name = "Myassembly" Useattributes = "False" >
< Include Key = "Other" Component = "Myassembly. component2" />
</ Assemblybatch >
</ Facility >
4) Load faclity
< Facility ID = "Batchregistration" >
< Addfacility ID = "Facility1" Type = "Myassembly. facility1, myassembly" />
< Addfacility ID = "Facility2" Type = "Myassembly. facility2, myassembly" />
</ Facility >
In fact, what this facility does is scan according to the configuration.ProgramSet and then dynamically loaded into the container, although very simple but flexible. For example, if you want to change the behavior of a component, you only need to replace the component DLL, And the other parts do not need to be re-compiled.
[Usage]
1) Create the Facility Configuration
<? XML version = "1.0" encoding = "UTF-8" ?>
< Configuration >
< Facilities >
< Facility ID = "Batchregistration" >
< Assemblybatch Name = "Myassembly" Useattributes = "True" />
</ Facility >
</ Facilities >
</ Configuration >
2) Declare the component class and edit it into the configuration file myassembly. dll.
[Castlecomponent ( " Comp1 " )]
Public Class Component1
{
Public Component1 ()
{
}
}
[Castlecomponent ("Comp2")]
Public ClassComponent2
{
PublicComponent2 ()
{
}
}
3) Use facility so that component1 and component2 are automatically loaded.
Iwindsorcontainer container = New Windsorcontainer ( " ../Castleconfig. xml " );
Container. addfacility ( " Batchregistration " , New Batchregistrationfacility ());