Beispiel #1
0
        static void Main(string[] args)
        {
            var serviceA = new ServiceA();
            var serviceB = new ServiceB();

            var serviceManager = new ServiceManager(serviceB);

            serviceManager.Start();

            //var serviceImpl = (ILog) service;
            //serviceImpl.Log("ididi");
            //IService serviceImpl2 = service;
            //serviceImpl2.Process();
            //service.Process();
            //service.CustomProcess();
        }
        static void Main(string[] args)
        {
            var serviceA = new ServiceA();
            var serviceB = new ServiceB();
            var serviceC = new ServiceC();

            serviceA.Handle();
            serviceA.Process();

            IService iservice = serviceA;

            iservice.Process();
            iservice = serviceB;
            iservice.Process();
            //iservice = serviceC; Error: ServiceC does not implement IService
            Start(serviceA);
            Start(serviceB);
            //Start(serviceC);

            var serviceManager = new ServiceManager(serviceA);

            serviceManager.Start();

            //IService service = serviceA;
            IService service = serviceB;
            //var serviceImpl = (ILog) service;
            var serviceImplV2 = service as ILog;

            if (serviceImplV2 != null)
            {
                serviceImplV2.Log("hello");
            }
            if (service is ILog)
            {
                var serviceImplv2 = (ILog)service;
                serviceImplv2.Log("hi");
            }

            //serviceImpl.Log("ididi");
            //IService serviceImpl2 = service;
            //serviceImpl2.Process();
            //service.Process();
            //service.CustomProcess();
        }