public void WTWIOC_Transient() { var container = new WTWIOC(); container.Register <ISampleLogic, SampleLogic>(LifetimeScopeType.Transient); container.Register <ISampleData, SampleData>(LifetimeScopeType.Transient); container.Register <ICalculator, Calculator>(LifetimeScopeType.Transient); var sampleLogic = container.Resolve <ISampleLogic>(); var sampleLogic2 = container.Resolve <ISampleLogic>(); Assert.NotNull(sampleLogic); Assert.NotNull(sampleLogic2); Assert.Equal(sampleLogic.InstanceId, sampleLogic2.InstanceId); }
public void WTWIOC_ResolveException() { Assert.Throws <Exception>(() => { var container = new WTWIOC(); var sampleLogic = container.Resolve <ISampleLogic>(); }); }
public object GetService(Type serviceType) { try { return(_container.Resolve(serviceType)); } catch { return(null); } }
public void WTWIOC_MultipleTransient() { var container = new WTWIOC(); container.Register <ISampleData, SampleData>(LifetimeScopeType.Transient); var container2 = container.AddContainer(); var sampleData = container.Resolve <ISampleData>(); var sampleData2 = container2.Resolve <ISampleData>(); Assert.NotNull(sampleData); Assert.NotNull(sampleData); Assert.NotEqual(sampleData.InstanceId, sampleData2.InstanceId); }
public void WTWIOC_AddMessage() { var container = new WTWIOC(); container.Register <ISampleData, SampleData>(); container.Register <ISampleLogic, SampleLogic>(); container.Register <ICalculator, Calculator>(); var sampleLogic = container.Resolve <ISampleLogic>(); string message = sampleLogic.AddMessage(4, 6); Assert.NotNull(message); Assert.Equal("4 + 6 = 10", message); }
public void WTWIOC_LoadSampleModel() { var container = new WTWIOC(); container.Register <ISampleData, SampleData>(); container.Register <ISampleLogic, SampleLogic>(); container.Register <ICalculator, Calculator>(); var sampleLogic = container.Resolve <ISampleLogic>(); var model = sampleLogic.LoadSampleModel(); Assert.NotNull(model); Assert.Equal(6, model.Length); }
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { return((IController)_container.Resolve(controllerType)); }