public Test Get(int id) { var test = _testFactory.Create(id); _logger.LogDebug($"Get called, returning new test object id={test?.Id}."); return(test); }
public void TestResolveMultitonFromFactoryClearInstances() { _iocContainer.RegisterMultiton <ITest, Test, MultitonScope>(); _iocContainer.RegisterFactory <ITestFactory>(); MultitonScope scope1 = new MultitonScope(); MultitonScope scope2 = new MultitonScope(); ITestFactory testFactory = _iocContainer.Resolve <ITestFactory>(); ITest resolvedTest1 = testFactory.Create(scope1); ITest resolvedTest2 = testFactory.Create(scope1); ITest resolvedTest3 = testFactory.Create(scope2); Assert.AreSame(resolvedTest1, resolvedTest2); Assert.AreNotSame(resolvedTest1, resolvedTest3); Assert.AreNotSame(resolvedTest2, resolvedTest3); testFactory.ClearMultitonInstance <ITest>(); ITest resolvedTest4 = testFactory.Create(scope1); ITest resolvedTest5 = testFactory.Create(scope2); Assert.AreNotSame(resolvedTest1, resolvedTest4); Assert.AreNotSame(resolvedTest2, resolvedTest4); Assert.AreNotSame(resolvedTest3, resolvedTest5); }
public void TestResolveFromFactoryWithByte() { _iocContainer.Register <ITest, TestByte>(); _iocContainer.RegisterFactory <ITestFactory>(); ITestFactory testFactory = _iocContainer.Resolve <ITestFactory>(); ITest createdTest = testFactory.Create(1); Assert.IsInstanceOf <TestByte>(createdTest); }
public void TestResolveFromFactoryWithDefaultParamCtor() { _iocContainer.Register <ITest, TestConstructor>(); _iocContainer.Register <Test, Test>(); //this registration is abnormal and should only be used in unit tests _iocContainer.RegisterFactory <ITestFactory>(); ITestFactory testFactory = _iocContainer.Resolve <ITestFactory>(); ITest createdTest = testFactory.Create(); Assert.IsInstanceOf <TestConstructor>(createdTest); }