/src/LinFu.IoC.Common/ImplementsAttribute.cs

http://github.com/philiplaureano/LinFu · C# · 51 lines · 19 code · 5 blank · 27 comment · 0 complexity · 0131c0d1a73691f5bb23e2f0fb7e3e6c MD5 · raw file

  1. using System;
  2. namespace LinFu.IoC.Configuration
  3. {
  4. /// <summary>
  5. /// The attribute used to specify how a service should be implemented
  6. /// in addition to its instancing behavior.
  7. /// </summary>
  8. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
  9. public class ImplementsAttribute : Attribute
  10. {
  11. /// <summary>
  12. /// The name to associate with the given service.
  13. /// </summary>
  14. public string ServiceName;
  15. /// <summary>
  16. /// Allows users to add services to a container using a
  17. /// given <paramref name="serviceType">service type</paramref>.
  18. /// </summary>
  19. /// <remarks>By default, each service will be created once per request.</remarks>
  20. /// <param name="serviceType">The <see cref="System.Type" /> of service to implement.</param>
  21. public ImplementsAttribute(Type serviceType) : this(serviceType, LifecycleType.OncePerRequest)
  22. {
  23. }
  24. /// <summary>
  25. /// Allows users to add services to a container using a
  26. /// given <paramref name="serviceType">service type</paramref> and
  27. /// <paramref name="lifeCycleType">lifecycle type</paramref>.
  28. /// </summary>
  29. /// <param name="serviceType">The <see cref="System.Type" /> of service to implement.</param>
  30. /// <param name="lifeCycleType">The instancing behavior to use with this implementation.</param>
  31. public ImplementsAttribute(Type serviceType, LifecycleType lifeCycleType)
  32. {
  33. ServiceType = serviceType;
  34. LifecycleType = lifeCycleType;
  35. }
  36. /// <summary>
  37. /// The type of service that will be implemented.
  38. /// </summary>
  39. public Type ServiceType { get; }
  40. /// <summary>
  41. /// The instancing behavior of the service instance.
  42. /// </summary>
  43. /// <seealso cref="LifecycleType" />
  44. public LifecycleType LifecycleType { get; }
  45. }
  46. }