/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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using LinFu.IoC;
  5. using LinFu.IoC.Configuration;
  6. using LinFu.IoC.Interfaces;
  7. namespace CarLibrary
  8. {
  9. [Implements(typeof(IVehicle), LifecycleType.OncePerRequest)]
  10. public class Car : IVehicle
  11. {
  12. private IEngine _engine;
  13. private IPerson _person;
  14. // Note: The loader can only work with default constructors
  15. public Car()
  16. {
  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. _engine.Start();
  33. Console.WriteLine("{0} says: I’m moving!", _person.Name);
  34. }
  35. public void Park()
  36. {
  37. if (_engine == null || _person == null)
  38. return;
  39. _engine.Stop();
  40. Console.WriteLine("{0} says: I’m parked!", _person.Name);
  41. }
  42. }
  43. }