public void TestContextSelf() { IDIContext context = new MiniocContext(); context.s().BindInstance <IDIContext>(context); context.s().Bind <IApple>(() => new YellowApple()); IApple apple = context.Resolve <IApple>(); Assert.That(apple is YellowApple); apple.TestContext(context); }
public void TestInjectionPropertiesNotClosedContextException() { IDIContext context = new MiniocContext(); context.s().BindInstance <IDIContext>(context); context.s().Bind <IApple>(() => new WrongApple()); Assert.Throws <MiniocException>(() => { context.Resolve <IApple>(); }); }
public void SingletoneFactorySameContextTest() { IDIContext context = new MiniocContext(); context.s().BindInstance <IDIContext>(context); context.s().Bind <IApple>(() => new GreenApple()); IApple apple1 = context.Resolve <IApple>(); IApple apple2 = context.Resolve <IApple>(); Assert.That(apple1 is GreenApple); Assert.That(apple2 is GreenApple); Assert.AreSame(apple1, apple2); }
private static IDIContext InternalCreateContext(IDIContext parent, string name) { IDIContext context = new MiniocContext(parent, name); // Binding context itself context.s().BindInstance <IDIContext>(context); return(context); }
public void TestSingletonPersistance() { MiniocContext context = new MiniocContext(); context.s().Bind <IOrange>(() => new BlueOrange()); SingletoneCreation(context); IOrange orange = context.Resolve <IOrange>(); Assert.AreEqual("my_test_orange", orange.tag); }
public void SingletoneSameContextTest() { MiniocContext context = new MiniocContext(); context.s().Bind <IOrange>(() => new RedOrange()); IOrange orange1 = context.Resolve <IOrange>(); IOrange orange2 = context.Resolve <IOrange>(); Assert.That(orange1 is RedOrange); Assert.That(orange2 is RedOrange); Assert.AreSame(orange1, orange2); }
public void SingletoneFactoryDifferentContextTest() { IDIContext context1 = new MiniocContext(); context1.s().Bind <IOrange>(() => new RedOrange()); IDIContext context2 = new MiniocContext(); context2.s().Bind <IOrange>(() => new RedOrange()); IOrange orange1 = context1.Resolve <IOrange>(); IOrange orange2 = context2.Resolve <IOrange>(); Assert.That(orange1 is RedOrange); Assert.That(orange2 is RedOrange); Assert.AreNotSame(orange1, orange2); }
public void SingletoneChainedContextTest() { MiniocContext context1 = new MiniocContext(); context1.s().Bind <IOrange>(() => new RedOrange()); MiniocContext context2 = new MiniocContext(context1); IOrange orange1 = context1.Resolve <IOrange>(); IOrange orange2 = context2.Resolve <IOrange>(); Assert.That(orange1 is RedOrange); Assert.That(orange2 is RedOrange); Assert.AreSame(orange1, orange2); context2.s().Bind <IOrange>(() => new RedOrange()); orange2 = context2.Resolve <IOrange>(); Assert.That(orange2 is RedOrange); Assert.AreNotSame(orange1, orange2); }