Castle IOC Container Insider story (next)

Source: Internet
Author: User

Main content

1. Componentmodelbuilder and Contributors

2. Contributors analysis

3. Handles analysis

4. Componentactivator Analysis

A Componentmodelbuilder and Contributors

In the previous article, the registration process for components was described, and the process of creating ComponentModel was to call contributor to process the component. Contributor is the first protagonist of our insider story, in Defaultcomponentmodelbuilder registered eight contributor, each contributor is specifically responsible for dealing with a certain aspect of things. As shown in the following code:

protected virtual void InitializeContributors()
{
  AddContributor( new ConfigurationModelInspector() );
  AddContributor( new LifestyleModelInspector() );
  AddContributor( new ConstructorDependenciesModelInspector() );
  AddContributor( new PropertiesDependenciesModelInspector() );
  AddContributor( new MethodMetaInspector() );
  AddContributor( new LifecycleModelInspector() );
  AddContributor( new ConfigurationParametersInspector() );
  AddContributor( new InterceptorInspector() );
}
// http://terrylee.cnblogs.com

1. Configurationmodelinspector: Used to process configuration, which uses Configurationstore to register in kernel to keep a component connected.

2. Lifestylemodelinspector: Lifecycle processing methods, mainly singleton, Thread, Transient, pooled, custom these can be specified in the configuration file, the following article will be mentioned.

3. Constructordependenciesmodelinspector: Handles constructor dependencies, collects all public constructors, and gives them to ComponentModel's constructors collection.

4. Propertiesdependenciesmodelinspector: Handles attribute dependencies, collects all writable properties, kernel may not set all the properties when the component is registered, or it may be set when the component is requested.

5. Methodmetainspector: Detects the method node in the component configuration, and each node is added to the ComponentModel's collection of sets.

6. Lifecyclemodelinspector: Processes the component lifecycle, that is, the behavior of component loading, initialization, and destruction, corresponding to three interfaces respectively: Iinitializable,isupportinitialize,idisposable, If the components implement these interfaces, the containers will automatically call them at different lifecycles.

7. Configurationparametersinspector: Handles the parameters element content in the configuration file, each parameters creates a Parametermodel, and added to the Parameters collection of ComponentModel.

8. Interceptorinspector: Handles information for interceptorattribute or interceptors elements in a configuration file.

In some cases, we may not need so many contributors, or we want to add custom contributors, we can use the following two methods Componentmodelbuilder to achieve contributors management:

public void AddContributor(IContributeComponentModelConstruction contributor)
{
  contributors.Add(contributor);
}
public void RemoveContributor(IContributeComponentModelConstruction contributor)
{
  contributors.Remove(contributor);
}
// http://terrylee.cnblogs.com

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.