PageRenderTime 17ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/ioc/ConstructorInjection/CarLibrary3/Car.cs

http://github.com/philiplaureano/LinFu
C# | 61 lines | 51 code | 10 blank | 0 comment | 8 complexity | b6ca45c4437a23adc25caacbc33b3d8a MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using CarLibrary3;
 5
 6using LinFu.IoC;
 7using LinFu.IoC.Configuration;
 8using LinFu.IoC.Interfaces;
 9
10namespace CarLibrary3
11{
12    public class Car : IVehicle, IInitialize
13    {
14        private IEngine _engine;
15        private IPerson _person;
16
17        public Car(IEngine engine, IPerson driver)
18        {
19            _engine = engine;
20            _person = driver;
21        }
22
23        public IEngine Engine
24        {
25            get { return _engine; }
26            set { _engine = value; }
27        }
28        public IPerson Driver
29        {
30            get { return _person; }
31            set { _person = value; }
32        }
33        public void Move()
34        {
35            if (_engine == null || _person == null)
36                return;
37
38            _engine.Start();
39            Console.WriteLine("{0} says: I�m moving!", _person.Name);
40        }
41        public void Park()
42        {
43            if (_engine == null || _person == null)
44                return;
45
46            _engine.Stop();
47            Console.WriteLine("{0} says: I�m parked!", _person.Name);
48        }
49
50        #region IInitialize Members
51
52        public void Initialize(IServiceContainer container)
53        {
54            _engine = container.GetService<IEngine>();
55            _person = container.GetService<IPerson>();
56        }
57
58        #endregion
59    }
60
61}