public void SelectUsingBusinessLogic_DirectSelection() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<IWatcher>().ImplementedBy<BirdWatcher>().Named("bird.watcher")).Register( Component.For<IWatcher>().ImplementedBy<SatiWatcher>().Named("astronomy.watcher")); var selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve<IWatcher>(), "default"); selector.Interest = Interest.Astronomy; Assert.IsInstanceOf(typeof(SatiWatcher), container.Resolve<IWatcher>(), "change-by-context"); selector.Interest = Interest.Biology; Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve<IWatcher>(), "explicit"); }
public void SubDependencyResolverHasHigherPriorityThanHandlerSelector() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For(typeof(Person)).LifeStyle.Is(LifestyleType.Transient)).Register( Component.For<IWatcher>().ImplementedBy<BirdWatcher>().Named("bird.watcher")).Register( Component.For<IWatcher>().ImplementedBy<SatiWatcher>().Named("astronomy.watcher")); var selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); container.Kernel.Resolver.AddSubResolver(new WatchSubDependencySelector()); selector.Interest = Interest.Biology; Assert.IsInstanceOf(typeof(SatiWatcher), container.Resolve<Person>().Watcher, "sub dependency should resolve sati"); Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve<IWatcher>(), "root dependency should resolve bird"); }
public void SelectUsingBusinessLogic_SubDependency() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For(typeof(Person)).LifeStyle.Is(LifestyleType.Transient)).Register( Component.For<IWatcher>().ImplementedBy<BirdWatcher>().Named("bird.watcher")).Register( Component.For<IWatcher>().ImplementedBy<SatiWatcher>().Named("astronomy.watcher")); var selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve<Person>().Watcher, "default"); selector.Interest = Interest.Astronomy; Assert.IsInstanceOf(typeof(SatiWatcher), container.Resolve<Person>().Watcher, "change-by-context"); selector.Interest = Interest.Biology; Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve<Person>().Watcher, "explicit"); }
public void SelectUsingBusinessLogic_DirectSelection() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For <IWatcher>().ImplementedBy <BirdWatcher>().Named("bird.watcher")).Register( Component.For <IWatcher>().ImplementedBy <SatiWatcher>().Named("astronomy.watcher")); var selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve <IWatcher>(), "default"); selector.Interest = Interest.Astronomy; Assert.IsInstanceOf(typeof(SatiWatcher), container.Resolve <IWatcher>(), "change-by-context"); selector.Interest = Interest.Biology; Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve <IWatcher>(), "explicit"); }
public void SubDependencyResolverHasHigherPriorityThanHandlerSelector() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For(typeof(Person)).LifeStyle.Is(LifestyleType.Transient)).Register( Component.For <IWatcher>().ImplementedBy <BirdWatcher>().Named("bird.watcher")).Register( Component.For <IWatcher>().ImplementedBy <SatiWatcher>().Named("astronomy.watcher")); var selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); container.Kernel.Resolver.AddSubResolver(new WatchSubDependencySelector()); selector.Interest = Interest.Biology; Assert.IsInstanceOf(typeof(SatiWatcher), container.Resolve <Person>().Watcher, "sub dependency should resolve sati"); Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve <IWatcher>(), "root dependency should resolve bird"); }
public void SelectUsingBusinessLogic_SubDependency() { IWindsorContainer container = new WindsorContainer(); container.Register(Component.For(typeof(Person)).LifeStyle.Is(LifestyleType.Transient)).Register( Component.For <IWatcher>().ImplementedBy <BirdWatcher>().Named("bird.watcher")).Register( Component.For <IWatcher>().ImplementedBy <SatiWatcher>().Named("astronomy.watcher")); var selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve <Person>().Watcher, "default"); selector.Interest = Interest.Astronomy; Assert.IsInstanceOf(typeof(SatiWatcher), container.Resolve <Person>().Watcher, "change-by-context"); selector.Interest = Interest.Biology; Assert.IsInstanceOf(typeof(BirdWatcher), container.Resolve <Person>().Watcher, "explicit"); }
public void SubDependencyResolverHasHigherPriorityThanHandlerSelector() { IWindsorContainer container = new WindsorContainer(); container .AddComponentLifeStyle<Person>(LifestyleType.Transient) .AddComponent<IWatcher, BirdWatcher>("bird.watcher") .AddComponent<IWatcher, SatiWatcher>("astronomy.watcher"); WatcherSelector selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); container.Kernel.Resolver.AddSubResolver(new WatchSubDependencySelector()); selector.Interest = Interest.Biology; Assert.IsInstanceOfType(typeof(SatiWatcher), container.Resolve<Person>().Watcher, "sub dependency should resolve sati"); Assert.IsInstanceOfType(typeof(BirdWatcher), container.Resolve<IWatcher>(), "root dependency should resolve bird"); }
public void SelectUsingBusinessLogic_SubDependency() { IWindsorContainer container = new WindsorContainer(); container .AddComponentLifeStyle<Person>(LifestyleType.Transient) .AddComponent<IWatcher, BirdWatcher>("bird.watcher") .AddComponent<IWatcher, SatiWatcher>("astronomy.watcher"); WatcherSelector selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); Assert.IsInstanceOfType(typeof(BirdWatcher), container.Resolve<Person>().Watcher, "default"); selector.Interest = Interest.Astronomy; Assert.IsInstanceOfType(typeof(SatiWatcher), container.Resolve<Person>().Watcher, "change-by-context"); selector.Interest = Interest.Biology; Assert.IsInstanceOfType(typeof(BirdWatcher), container.Resolve<Person>().Watcher, "explicit"); }
public void SelectUsingBusinessLogic_DirectSelection() { IWindsorContainer container = new WindsorContainer(); container .AddComponent<IWatcher, BirdWatcher>("bird.watcher") .AddComponent<IWatcher, SatiWatcher>("astronomy.watcher"); WatcherSelector selector = new WatcherSelector(); container.Kernel.AddHandlerSelector(selector); Assert.IsInstanceOfType(typeof(BirdWatcher), container.Resolve<IWatcher>(), "default"); selector.Interest = Interest.Astronomy; Assert.IsInstanceOfType(typeof(SatiWatcher), container.Resolve<IWatcher>(), "change-by-context"); selector.Interest = Interest.Biology; Assert.IsInstanceOfType(typeof(BirdWatcher), container.Resolve<IWatcher>(), "explicit"); }