zoukankan      html  css  js  c++  java
  • spring.net事件的注入

    1.c#代码
    TestObject source = new TestObject();
    TestEventHandler eventListener1 = new TestEventHandler();
    TestEventHandler eventListener2 = new TestEventHandler();
    source.Click += eventListener1.HandleEvent; // Adding the first event handler method to the event
    source.Click += eventListener2.HandleEvent; // Adding a second event handler method to the event
    source.OnClick(); // First eventListener1.HandleEvent is invoked, then eventListener2.HandleEvent
    
    2.触发事件,激发委托
    When OnClick() is invoked, the event is fired.
    public void OnClick()
    {
     if (Click != null)
     {
     Click(this, EventArgs.Empty); // Fire the event off to the registered handler methods
     }
    The IoC container
    Spring Framework (Version 1.3.2) 40
    }
    3.spring.net xml配置
    <object id="eventListener1" type="SpringdotNETEventsExample.TestEventHandler, SpringdotNETEventsExample">
     <!-- wired up to an event exposed on an instance -->
     <listener event="Click" method="HandleEvent">
     <ref object="source"/>
     </listener>
    </object>
    <object id="eventListener2" type="SpringdotNETEventsExample.TestEventHandler, SpringdotNETEventsExample">
     <!-- wired up to an event exposed on an instance -->
     <listener event="Click" method="HandleEvent">
     <ref object="source"/>
     </listener>
    </object>
    4.
    Regular expressions can be employed to wire up more than one handler method to an object that contains one
    or more events.
    
    <object id="eventListener" type="SpringdotNETEventsExample.TestEventHandler, SpringdotNETEventsExample">
     <listener method="Handle.+">
     <ref object="source"/>
     </listener>
    </object>
    Spring Framework (Version 1.3.2) 41
    <object id="eventListener" type="SpringdotNETEventsExample.TestEventHandler, SpringdotNETEventsExample">
     <!-- For the Click event, the HandleClick handler method will be invoked. -->
     <listener method="Handle${event}">
     <ref object="source"/>
     </listener>
    </object>
    5.3.3.4. Registering a handler method against an event name that contains a regular
    expression
    Finally, you can register an object's handler methods against a selection of events, filtering based on their name
    using a regular expression.
    <object id="eventListener" type="SpringdotNETEventsExample.TestEventHandler, SpringdotNETEventsExample">
     <listener method="HandleEvent" event="Cl.+">
     <ref object="source"/>
     </listener>
    </object>
    In this example the eventListener's HandleEvent handler method will be invoked for any event that begins with
    'Cl'
  • 相关阅读:
    PHP随机浮点数
    mysql中的包含语句INSTR的使用
    jquery全面判断是否IE6浏览器
    jquery中获取radio选中值的正确写法
    淘宝IP地址库API地址
    php判断是否是ajax提交 方法
    ejs模板引擎
    webpack配置非CMD规范的模块
    JavaScript中的浅拷贝和深拷贝
    css display:flex 属性
  • 原文地址:https://www.cnblogs.com/kexb/p/5919235.html
Copyright © 2011-2022 走看看