private static WTWIOC BuildContainer() { var container = new WTWIOC(); container.Register <HomeController, HomeController>(LifetimeScopeType.PerInstance); container.Register <ValuesController, ValuesController>(LifetimeScopeType.PerInstance); container.Register <ISampleData, SampleData>(LifetimeScopeType.Singleton); container.Register <ISampleLogic, SampleLogic>(LifetimeScopeType.Singleton); container.Register <ICalculator, Calculator>(LifetimeScopeType.Singleton); return(container); }
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_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); }
public static void Main(string[] args) { using (var container = new WTWIOC()) { container.Register <ISampleData, SampleData>(LifetimeScopeType.Singleton); container.Register <ISampleLogic, SampleLogic>(LifetimeScopeType.Singleton); container.Register <ICalculator, Calculator>(LifetimeScopeType.Singleton); using (var container2 = container.AddContainer()) { var test = container2.Resolve <ISampleLogic>(); var model = test.LoadSampleModel(); Console.WriteLine(test.AddMessage(4, 6)); Console.WriteLine(test.SubtractMessage(100239, 83837)); Console.WriteLine(test.MultiplyMessage(1000, 100)); Console.WriteLine(test.DivideMessage(1000000, 100)); } } }
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); }