public void AutoBind_Binds_Correctly_For_Interfaces_With_One_Implementor() { ComponentContainer container = new ComponentContainer(); container.AutoBind(Assembly.GetExecutingAssembly()); Assert.IsTrue(container.HasBinding<IHasOneImplementor>()); Assert.IsInstanceOf(typeof(HasOneImplementor), container.Resolve<IHasOneImplementor>()); }
public void AutoBind_Binds_Correctly_For_Interfaces_With_Multiple_Implementors_When_One_Implementor_Is_Marked_As_Default() { ComponentContainer container = new ComponentContainer(); container.AutoBind(Assembly.GetExecutingAssembly()); Assert.IsTrue(container.HasBinding<IBaz>()); Assert.IsInstanceOf(typeof(Baz1), container.Resolve<IBaz>()); }
public void AutoBind_With_InterfaceTypeFilter_Filters_Properly() { ComponentContainer container = new ComponentContainer(); container.AutoBind(Assembly.GetExecutingAssembly(), new AutoBindStrategy() { InterfaceTypeFilter = x => x.Name == "IBar" }); Assert.IsTrue(container.HasBinding<IBar>()); Assert.IsFalse(container.HasBinding<IFoo>()); }
public void Bind(ComponentContainer container, Type interfaceType, IList<Type> componentTypes) { if (container == null) throw new ArgumentNullException("container"); if (interfaceType == null) throw new ArgumentNullException("interfaceType"); if (componentTypes == null) throw new ArgumentNullException("componentTypes"); if (this.InterfaceTypeFilter != null && !this.InterfaceTypeFilter(interfaceType)) return; if (componentTypes.Count == 0) this.UnresolvedComponent(interfaceType, false); if (!container.HasBinding(interfaceType)) { var componentTypesEnumerable = componentTypes.AsEnumerable(); if (this.ComponentTypesFilter != null) componentTypesEnumerable = componentTypesEnumerable.Where(this.ComponentTypesFilter); if (componentTypesEnumerable.Count() == 1) // One implementor so we have the default binding { container.Bind(interfaceType).To(componentTypesEnumerable.First()).As(this.BindType); } else { Type defaultComponentType = this.FindDefaultComponentByAttribute(interfaceType, componentTypesEnumerable); if (defaultComponentType != null) { container.Bind(interfaceType).To(defaultComponentType).As(this.BindType); } else { this.UnresolvedComponent(interfaceType, true); } } } }
public void HasBinding_Returns_True_When_Binding_Exists() { ComponentContainer container = new ComponentContainer(); container.Bind<IFoo>().To<Foo1>(); Assert.IsTrue(container.HasBinding<IFoo>()); }
public void HasBinding_Returns_False_When_Binding_Does_Not_Exist() { ComponentContainer container = new ComponentContainer(); Assert.IsFalse(container.HasBinding<IFoo>()); }