mirror of https://github.com/AMT-Cheif/Stylet.git
Stitch EventAggregator into bootstrapper
This commit is contained in:
parent
5f655188c5
commit
6ee8927137
|
@ -25,7 +25,9 @@ namespace Stylet
|
||||||
protected virtual void ConfigureIoC(IStyletIoCBuilder builder)
|
protected virtual void ConfigureIoC(IStyletIoCBuilder builder)
|
||||||
{
|
{
|
||||||
builder.Autobind(AssemblySource.Assemblies);
|
builder.Autobind(AssemblySource.Assemblies);
|
||||||
|
|
||||||
builder.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
|
builder.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
|
||||||
|
builder.Bind<IEventAggregator>().To<EventAggregator>().InSingletonScope();
|
||||||
builder.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
|
builder.Bind<IViewManager>().To<ViewManager>().InSingletonScope();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,11 @@ namespace StyletUnitTests
|
||||||
public void Handle(M1 message) { this.ReceivedM1 = message; }
|
public void Handle(M1 message) { this.ReceivedM1 = message; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class C3 : IHandle<M1>
|
||||||
|
{
|
||||||
|
public void Handle(M1 message) { throw new Exception("Should not be called. Ever"); }
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void SubscribesAndDeliversExactMessage()
|
public void SubscribesAndDeliversExactMessage()
|
||||||
{
|
{
|
||||||
|
@ -54,5 +59,33 @@ namespace StyletUnitTests
|
||||||
Assert.AreEqual(message, target.ReceivedM1);
|
Assert.AreEqual(message, target.ReceivedM1);
|
||||||
Assert.AreEqual(message, target.ReceivedM2);
|
Assert.AreEqual(message, target.ReceivedM2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UnsubscribeUnsubscribes()
|
||||||
|
{
|
||||||
|
var ea = new EventAggregator();
|
||||||
|
var target = new C1();
|
||||||
|
ea.Subscribe(target);
|
||||||
|
ea.Unsubscribe(target);
|
||||||
|
|
||||||
|
var message = new M1();
|
||||||
|
ea.Publish(message);
|
||||||
|
|
||||||
|
Assert.IsNull(target.ReceivedMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TargetReferenceIsWeak()
|
||||||
|
{
|
||||||
|
var ea = new EventAggregator();
|
||||||
|
var target = new C3();
|
||||||
|
ea.Subscribe(target);
|
||||||
|
|
||||||
|
// Ugly, but it's the only way to test a WeakReference...
|
||||||
|
target = null;
|
||||||
|
GC.Collect();
|
||||||
|
|
||||||
|
Assert.DoesNotThrow(() => ea.Publish(new M1()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue