Castle IOC container Practice typedfactory Facility (II.)

Source: Internet
Author: User
Tags config

Main content

Principle Analysis of Typedfactory facility

......

In Typedfactory facility, there is a factoryentry class that is similar to the entity classes in our usual project development, which is used to record information about the factory, including the ID of the factory, the factory interface, the method of creation, and the method of destruction. This class is implemented as follows:

public class FactoryEntry
{
  private String _id;
  private Type _factoryInterface;
  private String _creationMethod;
  private String _destructionMethod;
  public FactoryEntry(String id, Type factoryInterface, String creationMethod, String destructionMethod)
  {
    // 省略了验证及异常处理
    _id = id;
    _factoryInterface = factoryInterface;
    _creationMethod = creationMethod;
    _destructionMethod = destructionMethod;
  }
  public String Id
  {
    get { return _id; }
  }
  public Type FactoryInterface
  {
    get { return _factoryInterface; }
  }
  public String CreationMethod
  {
    get { return _creationMethod; }
  }
  public String DestructionMethod
  {
    get { return _destructionMethod; }
  }
}

Typedfactoryfacility is also inherited from Abstractfacility, about facility's inheritance relationship I have already said in the previous article. Typedfactory facility first gets the type of the factory in the initialization, through the subsystem:

protected override void Init ()
{
Kernel.addcomponent ("Typed.fac.interceptor", typeof ( Factoryinterceptor));
Itypeconverter converter = (itypeconverter)
Kernel.getsubsystem (Subsystemconstants.conversionmanagerkey);
Addfactories (Facilityconfig, Converter);
}
Protected virtual void addfactories (IConfiguration facilityconfig, itypeconverter Converter)
{
if (FA Cilityconfig!= null)
{
foreach (iconfiguration config in facilityconfig.children["factories"). Children)
{
String id = config. attributes["id"];
String creation = CONFIG. attributes["Creation"];
String destruction = config. Attributes["Destruction"];
Type Factorytype = (type)
Converter. Performconversion (config. Attributes["Interface"], typeof (Type));
Try
{
Addtypedfactoryentry (
New Factoryentry (ID, factorytype, creation, des truction));
}
CATCH (Exception ex)
{
throw new ConfigurationException ("Invalid Factory entry in Configuration", ex); br>}
}

}

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.