【问题标题】:Castle Windsor: How do I wire up events in my configuration?Castle Windsor:如何在我的配置中连接事件?
【发布时间】:2008-12-04 20:27:40
【问题描述】:

我有这样的事情:

public interface IDeviceMonitor {
    int DeviceId { get; }
    event DeviceUpdatedHandler NewValueRecieved;
    void Start();
    void Stop();
}
public class DeviceInactivityDetector {
    ...
    public virtual void DeviceUpdated(IDeviceMonitor device, DeviceUpdatedArgs args) {
        ....
    }
}

目前,在我的应用程序启动文件中

var dm = IoC.Container.Resolve<IDeviceMonitor>();
var did = IoC.Container.Resolve<DeviceInactivityDetector>();
dm.NewValueRecieved += new DeviceUpdatedHandler(did.DeviceUpdated);

我想可以通过 xml 使用我的城堡配置文件进行此连接。但是怎么做呢?

【问题讨论】:

    标签: .net xml events castle-windsor


    【解决方案1】:

    使用 EventWiring Facility,您可以使用配置将组件的方法(订阅者)连接到组件的事件(发布者)。

    http://www.castleproject.org/container/facilities/v1rc3/eventwiring/index.html

    <configuration>
    <facilities>
        <facility 
            id="event.wiring"
            type="Castle.Facilities.EventWiring.EventWiringFacility, Castle.MicroKernel" />
    </facilities>
    
    <components>
        <component 
            id="DeviceInactivityDetector" 
            type=" . . ." />
    
        <component 
            id="IDeviceMonitor" 
            type=". . ." >
            <subscribers>
                <subscriber id="DeviceInactivityDetector" event="NewValueRecieved" handler="DeviceUpdated"/>
            </subscribers>
        </component>
    </components>
    

    【讨论】:

    • 我很痒,好像是时候再次查看这篇文章了。太棒了,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-11
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    • 2012-10-29
    • 1970-01-01
    相关资源
    最近更新 更多