版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】ASP.NET中Controller与Action如何使用
Controller&Action的定义和使用/upload/information/20210522/379/535400.pngController的查找机制Microsoft.AspNet.Mvc
Microsoft.AspNet.Mvc.Core
Microsoft.AspNet.Mvc.ModelBinding
Microsoft.AspNet.Mvc.Razor
Microsoft.AspNet.Mvc.Razor.Host
Microsoft.AspNet.Mvc.TagHelpers
Microsoft.AspNet.Mvc.Xml
Microsoft.AspNet.PageExecutionInstrumentation.InterfacesMicrosoft.AspNet.Mvc
Microsoft.AspNet.Mvc.Core
Microsoft.AspNet.Mvc.ModelBinding
Microsoft.AspNet.Mvc.Razor
Microsoft.AspNet.Mvc.Razor.Host
Microsoft.AspNet.Mvc.TagHelpers
Microsoft.AspNet.Mvc.Xml
Microsoft.AspNet.PageExecutionInstrumentation.Interfacespublic
interface
IAssemblyProvider
{
IEnumerable
CandidateAssemblies
{
get;
}
}services.AddMvc().WithControllersAsServices(new[]
{
typeof(MyController).Assembly,
typeof(ExternalPocoController).Assembly
});var
col
=
this.Resolver.GetRequiredService();
var
data
=
col.GetReferencingLibraries("Microsoft.AspNet.Mvc");protected
virtual
IEnumerableGetCandidateLibraries()
{
if
(ReferenceAssemblies
==
null)
{
return
Enumerable.Empty();
}
//
GetReferencingLibraries
returns
the
transitive
closure
of
referencing
assemblies
//
for
a
given
assembly.
return
ReferenceAssemblies.SelectMany(_libraryManager.GetReferencingLibraries)
.Distinct()
.Where(IsCandidateLibrary);
}Controller的判断public
interface
IControllerTypeProvider
{
IEnumerable
ControllerTypes
{
get;
}
}protected
internal
virtual
bool
IsController([NotNull]
TypeInfo
typeInfo,
[NotNull]
ISet
candidateAssemblies)
{
if
(!typeInfo.IsClass)
//
该类型必须是一个类
{
return
false;
}
if
(typeInfo.IsAbstract)
//
该类必须不是抽象类
{
return
false;
}
//
We
only
consider
public
top-level
classes
as
controllers.
IsPublic
returns
false
for
nested
//
classes,
regardless
of
visibility
modifiers
if
(!typeInfo.IsPublic)
//
该类必须是一个Public类(并且不嵌套),嵌套类不能作为Controller
{
return
false;
}
if
(typeInfo.ContainsGenericParameters)
//
该类不能是泛型类
{
return
false;
}
if
(!typeInfo.Name.EndsWith(ControllerTypeName,
StringComparison.OrdinalIgnoreCase)
&&
!DerivesFromController(typeInfo,
candidateAssemblies))
//
该类以Controller结尾,或继承于Controller基类,或其父类也是Controller。
{
return
false;
}
if
(typeInfo.IsDefined(typeof(NonControllerAttribute)))
//
该类不能设置NonControllerAttribute特性
{
return
false;
}
return
true;
}services.AddMvc().WithControllersAsServices(new[]
{
typeof(MyController),
typeof(ExternalPocoController)
});Action的查找机制public
Task
SelectAsync([NotNull]
RouteContext
context)
{
//
...
}public
Task
SelectAsync([NotNull]
RouteContext
context)
{
//
...
}public
IEnumerable
BuildActionModels([NotNull]
TypeInfo
typeInfo,
[NotNull]
MethodInfo
methodInfo)
{
if
(!IsAction(typeInfo,
methodInfo))
{
return
Enumerable.Empty();
}
//
省略其它代码
}protected
virtual
bool
IsAction([NotNull]
TypeInfo
typeInfo,
[NotNull]
MethodInfo
methodInfo)
{
//
The
SpecialName
bit
is
set
to
flag
members
that
are
treated
in
a
special
way
by
some
compilers
//
(such
as
property
accessors
and
operator
overloading
methods).
if
(methodInfo.IsSpecialName)
//
不能是特殊名称(如重载的操作符或属性访问器)
{
return
false;
}
if
(methodInfo.IsDefined(typeof(NonActionAttribute)))
//
不能声明NonActionAttribute特性
{
return
false;
}
//
Overriden
methods
from
Object
class,
e.g.
Equals(Object),
GetHashCode(),
etc.,
are
not
valid.
if
(methodInfo.GetBaseDefinition().DeclaringType
==
typeof(object))
//不能是重载的方法,比如Equals和GetHashCode
{
return
false;
}
//
Dispose
method
implemented
from
IDisposable
is
not
valid
if
(IsIDisposableMethod(methodInfo,
typeInfo))
//
不能是Dispose方法
{
return
false;
}
if
(methodInfo.IsStatic)
//
不能是静态方法
{
return
false;
}
if
(methodInfo.IsAbstract)
//
不能是抽象方法
{
return
false;
}
i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 桐城师范高等专科学校《贸易经济学》2025-2026学年期末试卷
- 泉州工艺美术职业学院《临床康复》2025-2026学年期末试卷
- 运城学院《债权法》2025-2026学年期末试卷
- 福建福耀科技大学《临床营养学》2025-2026学年期末试卷
- 芜湖航空职业学院《语言文字规范与应用》2025-2026学年期末试卷
- 扬州大学《中国教育思想史》2025-2026学年期末试卷
- 闽江学院《消费者行为学》2025-2026学年期末试卷
- 安徽国际商务职业学院《市场调查理论与方法》2025-2026学年期末试卷
- 乳制品加工原理与方法
- 比优特环保运营实践
- 综合办公室业务培训课件
- 2025年服装零售业库存管理规范
- 《增材制造工艺制订与实施》课件-SLM成形设备-光学系统
- 变电安规培训课件
- 第30讲 知识回归:2025高考化学试题教材溯源
- 医疗机构临床路径与诊疗规范
- 2026广东粤科金融集团校招面试题及答案
- LoRa无线技术教学课件
- 2025年英才计划面试真题及答案
- 犯罪主体课件
- 制造行业工厂设备部主管岗位招聘考试试卷及答案
评论
0/150
提交评论