我有这样的事情:
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与我的城堡配置文件进行连接。但是如何?
答案 0 :(得分:4)
使用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>