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