示例#1
0
        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);
        }
示例#2
0
 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 IDependencyScope BeginScope()
        {
            var newContainer = _container.AddContainer();

            return(new WTWIOC_ApiDependencyResolver(newContainer));
        }