PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/ioc/DependencyInjectionSample/CarLibrary/Car.cs

http://github.com/philiplaureano/LinFu
C# | 48 lines | 42 code | 5 blank | 1 comment | 8 complexity | 1d93e120ef73e6ea56da61e346b09ed3 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using LinFu.IoC;
 5using LinFu.IoC.Configuration;
 6using LinFu.IoC.Interfaces;
 7
 8namespace CarLibrary
 9{
10    [Implements(typeof(IVehicle), LifecycleType.OncePerRequest)]
11    public class Car : IVehicle
12    {
13        private IEngine _engine;
14        private IPerson _person;
15
16        // Note: The loader can only work with default constructors
17        public Car()
18        {
19        }
20        public IEngine Engine
21        {
22            get { return _engine; }
23            set { _engine = value; }
24        }
25        public IPerson Driver
26        {
27            get { return _person; }
28            set { _person = value; }
29        }
30        public void Move()
31        {
32            if (_engine == null || _person == null)
33                return;
34
35            _engine.Start();
36            Console.WriteLine("{0} says: I�m moving!", _person.Name);
37        }
38        public void Park()
39        {
40            if (_engine == null || _person == null)
41                return;
42
43            _engine.Stop();
44            Console.WriteLine("{0} says: I�m parked!", _person.Name);
45        }
46    }
47
48}