public void ContainerExtensions_overrideRegistration_should_override_a_previous_component() { var nss = new DelegateNamingSubSystem() { SubSystemHandler = (s, hs) => { var containsOverridableServices = hs.Where(h => h.ComponentModel.IsOverridable()) .Any(); if (containsOverridableServices && hs.Count() == 2) { return(hs.Single(h => !h.ComponentModel.IsOverridable())); } return(null); } }; var sut = new WindsorContainer(); sut.Kernel.AddSubSystem(SubSystemConstants.NamingKey, nss); sut.Register(Component.For <IFoo>().ImplementedBy <AFoo>().Overridable()); sut.Register(Component.For <IFoo>().ImplementedBy <AnOtherFoo>()); var foo = sut.Resolve <IFoo>(); foo.Should().Be.OfType <AnOtherFoo>(); }
protected override IServiceProvider CreateServiceProvider() { var nss = new DelegateNamingSubSystem() { SubSystemHandler = (s, hs) => { if (hs.Any(h => h.ComponentModel.IsOverridable())) { var nonOverridable = hs.Except(hs.Where(h => h.ComponentModel.IsOverridable())); if (nonOverridable.Any()) { return(nonOverridable.Single()); } } return(null); } }; this.container = new Castle.Windsor.WindsorContainer(); this.container.Kernel.AddSubSystem(SubSystemConstants.NamingKey, nss); this.container.Kernel.Resolver.AddSubResolver(new ArrayResolver(this.container.Kernel, true)); var wrapper = new ServiceProviderWrapper(this.container); var bootConventions = new BootstrapConventions(); this.container.Register( Component.For <IServiceProvider>() .Instance(wrapper) .Properties(pi => bootConventions.IgnorePropertyInjection(pi)) ); this.container.Register(Component.For <IWindsorContainer>().Instance(this.container)); this.container.Register ( Component.For <BootstrapConventions>() .Instance(bootConventions) .Properties(pi => bootConventions.IgnorePropertyInjection(pi)) ); this.container.AddFacility <Castle.Facilities.SubscribeToMessageFacility>(); this.container.AddFacility <InjectViewInRegionFacility>(); return(wrapper); }