public ICarProvider Create(User currentUser) { if (currentUser.FiscalStability == FiscalStability.MrMoneyBags) return new FerrariProvider(); else return new HondaProvider(); }
public void Can_properly_resolve_component_from_UsingFactory() { var user = new User { FiscalStability = FiscalStability.DirtFarmer }; Kernel.Register( Component.For<User>().Instance(user), Component.For<AbstractCarProviderFactory>(), Component.For<ICarProvider>() .UsingFactory((AbstractCarProviderFactory f) => f.Create(Kernel.Resolve<User>())) ); Assert.IsInstanceOf<HondaProvider>(Kernel.Resolve<ICarProvider>()); }
private void RegisterComponentsImplemtedByFerrari(User user) { kernel.Register( Component.For<User>().Named("currentUser").Instance(user), Component.For<AbstractCarProviderFactory>().Named("AbstractCarProviderFactory"), Component.For<ICarProvider>() .ImplementedBy<FerrariProvider>() .Attribute("factoryId").Eq("AbstractCarProviderFactory") .Attribute("factoryCreate").Eq("Create") ); }
public void can_register_without_providing_an_implementation() { var user = new User { FiscalStability = FiscalStability.DirtFarmer }; kernel.Register( Component.For<User>().Named("currentUser").Instance(user), Component.For<AbstractCarProviderFactory>().Named("AbstractCarProviderFactory"), Component.For<ICarProvider>() .Attribute("factoryId").Eq("AbstractCarProviderFactory") .Attribute("factoryCreate").Eq("Create") ); Assert.IsInstanceOf(typeof(HondaProvider), kernel.Resolve<ICarProvider>()); }
public void Can_properly_resolve_component_from_UsingFactoryMethod_with_kernel() { var user = new User { FiscalStability = FiscalStability.MrMoneyBags }; Kernel.Register( Component.For<User>().Instance(user), Component.For<ICarProvider>() .UsingFactoryMethod(k => new AbstractCarProviderFactory().Create(k.Resolve<User>())) ); Assert.IsInstanceOf<FerrariProvider>(Kernel.Resolve<ICarProvider>()); }