Castle IOC容器内幕故事(上)
摘要:在快速入门指南篇中,我们对于Castle IOC容器的使用已经有了一个直观的认识。本文将在这基础上进一步对Castle IOC容器的结构及其注册组件的过程做一个深入的分析,让我们开始Castle IOC的内幕故事吧。
{
_kernel.AddComponent(key, classType);
}
public virtual void AddComponent(String key, Type serviceType, Type classType)
{
_kernel.AddComponent(key, serviceType, classType);
}
// [url]http://terrylee.cnblogs.com[/url]
可以看到,WindsorContainer仅仅是调用了MicroKernel的方法来完成组件的注册,它只是对MicroKernel做了一次封装,核心的功能都由MicroKernel来完成,看一下MicroKernel中的AddComponent()方法的实现
{
if (key == null) throw new ArgumentNullException("key");
if (classType == null) throw new ArgumentNullException("classType");
ComponentModel model = ComponentModelBuilder.BuildModel(key, classType, classType, null);
RaiseComponentModelCreated(model);
IHandler handler = HandlerFactory.Create(model);
RegisterHandler(key, handler);
}
public virtual void AddComponent(String key, Type serviceType, Type classType)
{
if (key == null) throw new ArgumentNullException("key");
if (serviceType == null) throw new ArgumentNullException("serviceType");
if (classType == null) throw new ArgumentNullException("classType");
ComponentModel model = ComponentModelBuilder.BuildModel(key, serviceType, classType, null);
RaiseComponentModelCreated(model);
IHandler handler = HandlerFactory.Create(model);
RegisterHandler(key, handler);
}
// [url]http://terrylee.cnblogs.com[/url]
Type classType, IDictionary extendedProperties)
{
ComponentModel model = new ComponentModel(key, service, classType);
if (extendedProperties != null)
{
model.ExtendedProperties = extendedProperties;
}
foreach(IContributeComponentModelConstruction contributor in contributors)
{
contributor.ProcessModel( kernel, model );
}
return model;
}
// [url]http://terrylee.cnblogs.com[/url]
{
AddContributor( new ConfigurationModelInspector() );
AddContributor( new LifestyleModelInspector() );
AddContributor( new ConstructorDependenciesModelInspector() );
AddContributor( new PropertiesDependenciesModelInspector() );
AddContributor( new MethodMetaInspector() );
AddContributor( new LifecycleModelInspector() );
AddContributor( new ConfigurationParametersInspector() );
AddContributor( new InterceptorInspector() );
}
// [url]http://terrylee.cnblogs.com[/url]
{
ComponentModelDelegate eventDelegate = (ComponentModelDelegate) events[ComponentModelCreatedEvent];
if (eventDelegate != null) eventDelegate(model);
}
// [url]http://terrylee.cnblogs.com[/url]
{
IHandler handler = new DefaultHandler(model);
handler.Init(kernel);
return handler;
}
// [url]http://terrylee.cnblogs.com[/url]
Castle的官方网站[url]http://www.castleproject.org[/url]
本文转自lihuijun51CTO博客,原文链接:http://blog.51cto.com/terrylee/67672 ,如需转载请自行联系原作者
Castle IOC容器内幕故事(上)相关推荐
- Castle实践9-在Castle IOC容器中使用AspectSharp(全面剖析AspectSharp Facility)
在"Castle实践8"介绍了A#的使用方法,那么A#如何和Castle IOC容器结合起来使用呢?在Castle的官方falicicies库中,提供了AspectSharp Fa ...
- Castle IOC容器快速入门
摘要:IOC模式是近年来非常流行的一种模式,相信大家都不陌生了,如果你还不是很熟悉的话,可以看看Martin Fowler大师的文章http://martinfowler.com/articles/i ...
- Castle IOC容器实践之TypedFactory Facility(一)
摘要:相信大家对于Factory Method设计模式都已经不陌生了,在Factory Method中,对于每一个具体的产品都需要有一个与之对应的工厂类,随着具体的产品越来越多,我们对于工厂类的管理就 ...
- Castle IOC容器与Spring.NET配置之比较
我本人对于Spring.NET并不了解,本文只是通过一个简单的例子来比较一下两者配置之间的区别.在Castle IOC容器中,提出了自动装配(Auto-Wiring)的概念,即由容器自动管理组件之间的 ...
- Castle IOC容器实践之EnterpriseLibrary Configuration Facility
摘要:EnterpriseLibrary Configuration Facility就好像是在容器和数据类之间的桥,让我们可以轻松得去读取和操作配置文件.熟悉Enterprise Library的人 ...
- [Spring 深度解析]第6章 Spring的IoC容器系列
6. Spring的IoC容器系列 IoC容器为开发者管理对象之间的依赖关系提供了很多便利和基础服务.有许多IoC容器供开发者选择,SpringFramework的IoC核心就是其中一个,它是开源 ...
- 抛开 Spring 去理解 IOC 思想:原来 IOC 容器这么简单
很多小伙伴们看到标题可能就会想到抛开 Spring 就不会存在 IOC 思想了,其实不然在接下来的文章中就会讲述到. 很多小伙伴在理解 IOC 的时候通常会和 Spring 放到一起去学习,首先呢 S ...
- ioc spring 上机案例_抛开Spring去理解IOC思想 - 原来IOC容器这么简单
很多小伙伴们看到标题可能就会想到抛开Spring就不会存在IOC思想了,其实不然在接下来的文章中就会讲述到. 很多小伙伴在理解IOC的时候通常会和Spring放到一起去学习,首先呢Spring设计的非 ...
- 【Spring】IoC容器系列的设计与实现:BeanFactory和ApplicationContext
在Spring IoC容器的设计中,我们可以看到两个主要的容器系列,一个是实现BeanFactory接口的简单容器系列,这系列容器只实现了容器的最基本功能,另一个是ApplicationContext ...
最新文章
- mysql or的效率_Mysql比较exists与in以及or的效率分析
- Flink从Kafka 0.8中读取多个Topic时的问题
- ASP.NET MVC 4高级编程(第4版)
- maven工程src/main/java目录无法创建问题
- P3385 【模板】负环
- java设置断点,在Java中设置断点
- redis学习之三配置文件redis.conf 的含义
- vue3打包后无法加载页面
- 判断表达式是否正确闭合,返回未闭合元素的下标。
- Linux 的字符串截取很有用。有八种方法。
- android6.0系统Healthd深入分析
- 腾讯产培课堂|产品经理岗位解析×面试指南
- SVM多分类的几种方式
- 飞思卡尔单片机学习记录(一)
- java关闭自动更新_怎么关闭java自动更新
- “双一流”高校,整体搬迁!
- 笔记本安装win10+ubuntu双系统超详细教程
- 阿里云Centos7修改22默认端口
- 大华SDK+JAVA+4g网络摄像头进行二次开发
- 基于红外遥控的arduino遥控小车
热门文章
- SAP Forecasting and Replenishment for Retail – A short Overview【中英文双语版】
- 南京、苏州、杭州、上海你更喜欢哪座城市?
- 专利申请超全球!新崛起的中国人工智能,还有哪些你不知道的事
- 人工智能基础-概率分布与函数的基础定义
- Caffe 运行平台支持DenseNet模型
- 头条丨2017年人工智能现七大走向
- 没有安装python如何使用anaconda运行python命令行
- 死前真的会有「跑马灯」,人类首次同步测量大脑濒死状态
- 华人一作统一「视觉-语言」理解与生成:一键生成图像标注,完成视觉问答,Demo可玩...
- 元宇宙不是下一代互联网,而是人类群体思维空间或梦境世界的具现