ServiceAttribute.cs 897 B

1234567891011121314151617181920212223242526272829303132
  1. using Microsoft.Extensions.DependencyInjection;
  2. using System;
  3. namespace FastGithub
  4. {
  5. /// <summary>
  6. /// 表示服务特性
  7. /// </summary>
  8. [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
  9. public sealed class ServiceAttribute : Attribute
  10. {
  11. /// <summary>
  12. /// 获取服务的生命周期
  13. /// </summary>
  14. public ServiceLifetime Lifetime { get; }
  15. /// <summary>
  16. /// 获取或设置注册的服务类型
  17. /// 为null直接使得当前类型
  18. /// </summary>
  19. public Type? ServiceType { get; set; }
  20. /// <summary>
  21. /// 将当前实现类型注册为服务的特性
  22. /// </summary>
  23. /// <param name="lifetime">生命周期</param>
  24. public ServiceAttribute(ServiceLifetime lifetime)
  25. {
  26. Lifetime = lifetime;
  27. }
  28. }
  29. }