public void CanBindAndGet() { const string customSingletonId = "customSingleton"; const string customPrototypeId = "customPrototype"; TestEmptyClass defaultSingletonEmptyObj = new TestEmptyClass(); TestEmptyClass customSingletonEmptyObj = new TestEmptyClass(); TestEmptyClass customPrototypeEmptyObj = new TestEmptyClass(); Injector injector = new Injector(); injector.Bind <TestEmptyClass>(defaultSingletonEmptyObj); injector.Bind <TestEmptyClass>(customSingletonEmptyObj, customSingletonId); injector.Bind <TestEmptyClass>(customPrototypeEmptyObj, InstantiationType.PROTOTYPE, customPrototypeId); // Default singleton TestEmptyClass resultDefaultSingletonObj = injector.Get <TestEmptyClass>(); Assert.AreSame(defaultSingletonEmptyObj, resultDefaultSingletonObj); // custom singleton TestEmptyClass resultCustomSingletonObj = injector.Get <TestEmptyClass>(customSingletonId); Assert.AreSame(customSingletonEmptyObj, resultCustomSingletonObj); Assert.AreNotSame(defaultSingletonEmptyObj, resultCustomSingletonObj); // custom prototype TestEmptyClass resultCustomPrototypeObj = injector.Get <TestEmptyClass>(customPrototypeId); Assert.AreNotSame(customPrototypeEmptyObj, resultCustomPrototypeObj); Assert.AreEqual(typeof(TestEmptyClass), resultCustomPrototypeObj.GetType()); }
public void CanBindNewInstance() { const string defaultId = "default"; const string childId = "child"; Injector injector = new Injector(); injector.BindNewInstance <TestEmptyClass>(); injector.BindNewInstance <TestEmptyClass, TestEmptyChildClass>(); Assert.IsTrue(injector.ContainsCustomId <TestEmptyClass>(defaultId)); Assert.IsTrue(injector.ContainsCustomId <TestEmptyClass>(childId)); TestEmptyClass childClass = injector.Get <TestEmptyClass>(childId); Assert.AreEqual(typeof(TestEmptyChildClass), childClass.GetType()); }
public void CanGet() { TestEmptyClass defaultSingleton = StaticContainer.Get <TestEmptyClass>(); Assert.AreSame(DEFAULT_EMPTY_CLASS, defaultSingleton); TestEmptyClass customSingleton = StaticContainer.Get <TestEmptyClass>(CUSTOM_ID); Assert.AreSame(CUSTOM_EMPTY_CLASS, customSingleton); TestEmptyClass prototype = StaticContainer.Get <TestEmptyClass>(PROTOTYPE_ID); Assert.AreNotSame(PROTOTYPE_EMPTY_CLASS, prototype); Assert.AreEqual(typeof(TestEmptyClass), prototype.GetType()); TestEmptyChildClass childClass = (TestEmptyChildClass)StaticContainer.Get <TestEmptyClass>(SUBCLASS_ID); Assert.AreSame(EMPTY_CHILD_CLASS, childClass); }
public TestClassWithCustomConstructor([ID("custom")] TestEmptyClass cls) { this.TestEmptyCls = cls; }
private TestClassWithCustomConstructor() { this.TestEmptyCls = null; }
public TestClassWithConstructor(TestEmptyClass cls) { this.TestEmptyCls = cls; }
public TestClassWithConstructorInjectionFail(float testFloat, TestEmptyClass emptyCls) { this.TestFloat = testFloat; this.TestEmptyCls = emptyCls; }
public TestClassWithConstructorInjection(TestEmptyClass emptyClass, [ID("custom")] int intValue) { _intValue = intValue; EmptyClass = emptyClass; }