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.

76 lines
2.2 KiB

using Apewer.Network;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
namespace Apewer.Web
{
/// <summary>API 上下文。</summary>
public sealed class ApiContext
{
#region 构造参数
private ApiInvoker _invoker = null;
private ApiProvider _provider = null;
private ApiEntries _entries = null;
private DateTime _beginning = DateTime.Now;
private ApiOptions _options = null;
/// <summary>此上下文启动的时间。</summary>
public DateTime Beginning { get => _beginning; }
/// <summary>API 调用器。</summary>
public ApiInvoker Invoker { get => _invoker; }
/// <summary>API 提供程序。</summary>
public ApiProvider Provider { get => _provider; }
/// <summary>API 入口集。</summary>
public ApiEntries Entries { get => _entries; }
/// <summary>API 选项。</summary>
public ApiOptions Options { get => _options; }
#endregion
#region 执行过程中产生的内容
/// <summary>API 行为。</summary>
public ApiAction ApiAction { get; internal set; }
/// <summary>API 请求。</summary>
public ApiRequest Request { get; internal set; }
/// <summary>API 响应。</summary>
public ApiResponse Response { get; internal set; }
/// <summary>API 控制器实例。</summary>
public ApiController Controller { get; internal set; }
/// <summary>执行的方法。</summary>
public MethodInfo MethodInfo { get; internal set; }
#endregion
internal ApiContext(ApiInvoker invoker, ApiProvider provider, ApiEntries entries)
{
if (invoker == null) throw new ArgumentNullException(nameof(invoker));
if (provider == null) throw new ArgumentNullException(nameof(provider));
if (entries == null) throw new ArgumentNullException(nameof(entries));
_invoker = invoker;
_provider = provider;
_entries = entries;
_options = invoker.Options ?? new ApiOptions();
}
}
}