public void DoesResolveFromFactoryWithInjectContext() { Container container = new Container(); container.Bind <ISomeConsumer>().To <SomeConsumer>().AsSingleton(); container.Bind <ISomeOtherConsumer>().To <SomeOtherConsumer>().AsSingleton(); container.Bind <ISomeProviderFactory>().To <SomeProviderFactory>().AsSingleton(); container.Bind <ISomeProvider>().FromFactory <ISomeProviderFactory, ISomeProvider>().AsTransient(); ISomeConsumer consumer = container.Resolve <ISomeConsumer>(); ISomeOtherConsumer otherConsumer = container.Resolve <ISomeOtherConsumer>(); Assert.AreNotEqual(consumer.Provider, otherConsumer.Provider, "Provider did not resolve as transient"); Assert.AreEqual(consumer.Provider.ConsumerType, typeof(SomeConsumer), "Incorrect consumer type"); Assert.AreEqual(otherConsumer.Provider.ConsumerType, typeof(SomeOtherConsumer), "Incorrect consumer type"); }
public void DoesResolveFromFactoryMethodWithInjectContext() { Container container = new Container(); bool didCallFactoryMethod = false; container.Bind <ISomeConsumer>().To <SomeConsumer>().AsSingleton(); container.Bind <ISomeProvider>().To <SomeProvider>().FromFactoryMethod(delegate(IInjectContext injectContext) { Assert.AreEqual(typeof(SomeConsumer), injectContext.DeclaringType, "incorrect context declaring type"); didCallFactoryMethod = true; return(new SomeProvider()); }).AsTransient(); ISomeConsumer consumer = container.Resolve <ISomeConsumer>(); Assert.IsTrue(didCallFactoryMethod, "did not resolve using factory method"); }