You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. namespace Apewer.Web
  4. {
  5. /// <summary></summary>
  6. public abstract class ApiController : IDisposable
  7. {
  8. internal ApiApplication Application = null;
  9. internal ApiFunction Function = null;
  10. private ApiRequest _request = null;
  11. private ApiResponse _response = null;
  12. private bool _allow = true;
  13. /// <summary>获取 API 请求模型。</summary>
  14. public virtual ApiRequest Request
  15. {
  16. get { return _request; }
  17. internal set { _request = value; }
  18. }
  19. /// <summary>获取 API 响应模型。</summary>
  20. public virtual ApiResponse Response
  21. {
  22. get
  23. {
  24. if (_response == null) _response = new ApiResponse();
  25. return _response;
  26. }
  27. internal set { _response = value; }
  28. }
  29. /// <summary>获取或设置初始化方法。</summary>
  30. public virtual Action AfterInitialized { get; set; }
  31. /// <summary>获取或设置默认功能,在匹配 Function 失败后调用。</summary>
  32. public virtual Action DefaultFunction { get; set; }
  33. /// <summary>默认允许调用 Function。当存在 Independent 特性时 Invoker 将忽略此值,且不调用 Function。</summary>
  34. public virtual bool AllowFunction
  35. {
  36. get { return _allow; }
  37. protected set { _allow = value; }
  38. }
  39. /// <summary></summary>
  40. public virtual void Dispose() { }
  41. void InvalidFunction() => Response.Error("指定的 Function 无效。");
  42. }
  43. }