Spring.NET学习笔记(3)-注册事件注入
来源:互联网 发布:金融网络销售装美女 编辑:程序博客网 时间:2024/05/29 19:28
事件注入是.net版本的spring特有的,其实现方式是反向的,同时支持静态事件和实例事件
<object id="source" type="Spring.Objects.TestObject, Spring.Core.Tests"/><object id="staticEventListener" type="Spring.Objects.TestEventHandler, Spring.Core.Tests"> <!-- wired up to a static event --> <listener event="StaticClick" method="HandleEvent"> <ref type="Spring.Objects.TestObject, Spring.Core.Tests"/> </listener></object><object id="instanceEventListener" type="Spring.Objects.TestEventHandler, Spring.Core.Tests"> <!-- wired up to an event exposed on an instance --> <listener event="Click" method="HandleEvent"> <ref object="source"/> </listener></object>
internal class TestEventHandler { public virtual void HandleEvent (object sender, EventArgs e) { _eventWasHandled = true; } public virtual bool EventWasHandled { get { return _eventWasHandled; } } protected bool _eventWasHandled; }
public event EventHandler Click;public static event EventHandler StaticClick;/// <summary>/// Public method to programmatically raise the <event>Click</event> event/// while testing./// </summary>public void OnClick(){ if (Click != null) { Click(this, EventArgs.Empty); }}/// <summary>/// Public method to programmatically raise the <b>static</b>/// <event>Click</event> event while testing./// </summary>public static void OnStaticClick(){ if (TestObject.StaticClick != null) { TestObject.StaticClick(typeof (TestObject), EventArgs.Empty); }}
Server测试
[Test]public virtual void InstanceEventWiring(){ DefaultListableObjectFactory factory = new DefaultListableObjectFactory(); XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory); reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring.xml", GetType())); ITestObject source = factory["source"] as ITestObject; TestEventHandler instanceHandler = factory["instanceEventListener"] as TestEventHandler; // raise the event... handlers should be notified at this point (obviously) source.OnClick(); Assert.IsTrue(instanceHandler.EventWasHandled, "The instance handler did not get notified when the instance event was raised (and was probably not wired up in the first place).");}
- Spring.NET学习笔记(3)-注册事件注入
- Spring.NET学习笔记(3)-注册事件注入
- SPRING.NET 1.3.2 学习15--事件注入
- Spring.NET学习笔记(2)-依赖注入细节
- Spring.NET学习笔记(1)-基本依赖注入
- Spring.NET学习笔记(1)-基本依赖注入
- Spring.NET学习笔记(2)-依赖注入细节
- spring.net学习笔记1--依赖对象注入
- ASP.NET_MVC使用Spring.Net.MVC依赖注入学习笔记
- spring学习笔记3--依赖注入对象
- Spring 学习笔记 ----依赖注入
- [学习笔记]Spring依赖注入
- 学习笔记:Spring注解注入
- Spring学习笔记 依赖注入
- 【Spring学习笔记】依赖注入
- Spring学习笔记(4.Spring注入)
- Spring.NET 学习笔记
- Spring.NET学习笔记
- 《Java编程思想》读书笔记(1)
- 表格排序sortable.jsp修改版
- Spring.NET学习笔记(6)-基础AOP
- Spring.NET学习笔记(5)-对象生命周期和创建者对象
- Spring.NET学习笔记(4)-对象作用域和类型转换
- Spring.NET学习笔记(3)-注册事件注入
- Spring.NET学习笔记(2)-依赖注入细节
- Spring.NET学习笔记(1)-基本依赖注入
- NHibernate Step By Step(7)-映射集合类型
- NHibernate Step By Step(6)-关联关系
- NHibernate Step By Step(5)-实体表现模式
- NHibernate Step By Step(4)-事件(Event)
- NHibernate Step By Step(3)-数据操作回调方法(拦截器)
- NHibernate Step By Step(2)-继承映射