DryIOC Event Aggregator

余生长醉 提交于 2019-12-04 11:43:18

It is pretty easy to do in DryIoc (I am an owner). Here I will speak about V2 RC version.

Given that you've replaced IContainer dependency with IResolver which is automatically injected:

var container = new Container();

container.Register<IEventDispatcher, DryIocEventDispatcher>();
container.RegisterMany<ScoringService>(Reuse.Singleton);
container.RegisterMany<RenderingService>();

var eventDispatcher = container.Resolve<IEventDispatcher>();

eventDispatcher.Dispatch(new ZoneDestroyedEventArgs());
eventDispatcher.Dispatch(new ZoneCreatedEventArgs());

RegisterMany will take care of handlers being reused as Singleton and will return the same instance for both Handles<> interfaces.

Additionally you may use RegisterMapping to add/map IHandles<> service to already registered implementation.

DryIoc has even more to help with EventAggregator implementation.

Also here is solution for problem similar to yours.

The gist with your working example.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!