コード例 #1
0
 public void TestLegacy()
 {
     ILogService logService = new LogService();
     Executer executer1 = new Executer(logService, new FileService());
     executer1.Run(5.0);
     Executer executer2 = new Executer(logService, new FileService());
     executer2.Run(5.0);
 }
コード例 #2
0
        public void TestUnity()
        {
            using (UnityContainer unity = new UnityContainer())
            {
                unity.RegisterInstance<ILogService>(new LogService());
                unity.RegisterType<IFileService, FileService>(new ContainerControlledLifetimeManager());

                Executer executer1 = unity.Resolve<Executer>();
                Executer executer2 = unity.Resolve<Executer>();
                Executer executer3 = new Executer(unity.Resolve<ILogService>(), unity.Resolve<IFileService>());

                Console.WriteLine("fileService: {0}", unity.Resolve<IFileService>().GetHashCode());
                Console.WriteLine("fileService: {0}", unity.Resolve<IFileService>().GetHashCode());

                Console.WriteLine(executer1.Run(5));
                Console.WriteLine(executer2.Run(10));
                Console.WriteLine(executer3.Run(20));
            }
        }