public void Init() { this.injector = new InjectionContainer(); this.binder = this.injector as IBinder; //Binds some objects to use on tests. binder.Bind <IMockInterface>().To <MockIClassWithAttributes>(); binder.Bind <MockIClassWithoutAttributes>().ToSingleton().As("singleton"); binder.Bind <MockIClass>().ToSingleton(); this.containerIdentifierTests = new InjectionContainer(); var mockClass1 = new MockIClass() { property1 = "MockClass1" }; var mockClass2 = new MockIClassWithoutAttributes() { property1 = "MockClass2" }; var mockClass3 = new MockIClassWithAttributes() { property1 = "MockClass3" }; this.containerIdentifierTests.Bind <MockIClass>().To(mockClass1).As(TestIdentifier.MockClass); this.containerIdentifierTests.Bind <MockIClassWithoutAttributes>().To(mockClass2).As(TestIdentifier.MockClass); this.containerIdentifierTests.Bind <MockIClassWithAttributes>().To(mockClass3).As(TestIdentifier.MockClass); this.containerIdentifierTests.Bind <IMockInterface>().To(mockClass1).As(TestIdentifier.MockClass1); this.containerIdentifierTests.Bind <IMockInterface>().To(mockClass2).As(TestIdentifier.MockClass2); this.containerIdentifierTests.Bind <IMockInterface>().To(mockClass3).As(TestIdentifier.MockClass3); this.containerIdentifierTests.Bind <IMockInterface>().To <MockIClass>().As(TestIdentifier.MockClassSingle); }
public object Create(InjectionContext context) { var obj = new MockIClassWithAttributes(); obj.field1 = obj.field2 = obj.field3 = "Created from a Factory"; return(obj); }
public void TestBindingToInstanceFromInterface() { var binder = new Binder(); var instance = new MockIClassWithAttributes(); binder.Bind<IMockInterface>().To<MockIClassWithAttributes>(instance); var bindings = binder.GetBindingsFor<IMockInterface>(); Assert.AreEqual(1, bindings.Count); Assert.AreEqual(BindingInstance.Singleton, bindings[0].instanceType); Assert.AreEqual(typeof(IMockInterface), bindings[0].type); Assert.AreEqual(instance, bindings[0].value); }
public void TestBindingToInstanceFromInterface() { var binder = new Binder(); var instance = new MockIClassWithAttributes(); binder.Bind <IMockInterface>().To <MockIClassWithAttributes>(instance); var bindings = binder.GetBindingsFor <IMockInterface>(); Assert.AreEqual(1, bindings.Count); Assert.AreEqual(BindingInstance.Singleton, bindings[0].instanceType); Assert.AreEqual(typeof(IMockInterface), bindings[0].type); Assert.AreEqual(instance, bindings[0].value); }
public void TestUnbindByInstance() { var binder = new Binder(); var instance = new MockIClassWithAttributes(); binder.Bind <MockClassToDepend>().ToSelf(); binder.Bind <MockClassToDepend>().ToSelf().WhenIntoInstance(instance); binder.Bind <IMockInterface>().To(instance).As("Mock1"); binder.UnbindInstance(instance); var bindings = binder.GetBindings(); Assert.AreEqual(1, bindings.Count); Assert.AreEqual(typeof(MockClassToDepend), bindings[0].type); }
public void Init() { this.injector = new InjectionContainer(); this.binder = this.injector as IBinder; //Binds some objects to use on tests. binder.Bind<IMockInterface>().To<MockIClassWithAttributes>(); binder.Bind<MockIClassWithoutAttributes>().ToSingleton().As("singleton"); binder.Bind<MockIClass>().ToSingleton(); this.containerIdentifierTests = new InjectionContainer(); var mockClass1 = new MockIClass() { property1 = "MockClass1" }; var mockClass2 = new MockIClassWithoutAttributes() { property1 = "MockClass2" }; var mockClass3 = new MockIClassWithAttributes() { property1 = "MockClass3" }; this.containerIdentifierTests.Bind<MockIClass>().To(mockClass1).As(TestIdentifier.MockClass); this.containerIdentifierTests.Bind<MockIClassWithoutAttributes>().To(mockClass2).As(TestIdentifier.MockClass); this.containerIdentifierTests.Bind<MockIClassWithAttributes>().To(mockClass3).As(TestIdentifier.MockClass); this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass1).As(TestIdentifier.MockClass1); this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass2).As(TestIdentifier.MockClass2); this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass3).As(TestIdentifier.MockClass3); this.containerIdentifierTests.Bind<IMockInterface>().To<MockIClass>().As(TestIdentifier.MockClassSingle); }
public object Create(InjectionContext context) { var obj = new MockIClassWithAttributes(); obj.field1 = obj.field2 = obj.field3 = "Created from a Factory"; return obj; }