ASP NET Core Net mezhangwenqing org NET Framework

  • Slides: 21
Download presentation
ASP. NET Core�用生命周期指北 �文清 . Net西安社区 me@zhangwenqing. org

ASP. NET Core�用生命周期指北 �文清 . Net西安社区 me@zhangwenqing. org

概念和体系:. NET Framework, . NET Core, ASP. NET Core �片出自 2016年. NET Standard介� https:

概念和体系:. NET Framework, . NET Core, ASP. NET Core �片出自 2016年. NET Standard介� https: //blogs. msdn. microsoft. com/dotnet/2016/09/26/introducing-net-standard/

Runtime, SDK, Package • Runtime(运行�),. NET Core Runtime • Core. CLR,包含JIT(Just In Time��器), ILAsm(.

Runtime, SDK, Package • Runtime(运行�),. NET Core Runtime • Core. CLR,包含JIT(Just In Time��器), ILAsm(. NET IL中��言��程序), ILDasm(. NET IL中��言反��程序), Test. Host(corehost. exe��控制台�行器), mscorelib,一 系列原生�型和内部�型(包括. NET GC) • Core. FX,System. Collections,System. IO,System. Xml等等其他�件 • SDK,. NET Core SDK • • CLI,默�启�器,脚手架 具等 Roslyn,C#和VB. NET��器和�言支持 SKD,MSBuild任�支持等其他 VS必要�件 Fsc,F#�言支持 • Package • nuget (v 3 json) • ASP. NET Core所有的Assembly以nuget Package形式分�

依�注入 (Dependency Injection) • • ASP. NET Core中的依�称� Service 通�抽象接口来解耦�� 默�通�构造函数注入 提供内置Services • https:

依�注入 (Dependency Injection) • • ASP. NET Core中的依�称� Service 通�抽象接口来解耦�� 默�通�构造函数注入 提供内置Services • https: //docs. microsoft. com/en-us/aspnet/core/fundamentals/dependencyinjection? view=aspnetcore-2. 1#framework-provided-services • 提供三种Service生命周期:短�( Transient,每次�建一个�例),作用域内( Scoped,每�求�建一个�例),�例( Singleton) • 支持三方Service Container,例如Autofac • 在Configure. Service中返回 IService. Provider

中�件 (Middleware)的三种写法 app. Use( (context, next) => { next(); }); app. Map(“/endpoint”, (app) =>

中�件 (Middleware)的三种写法 app. Use( (context, next) => { next(); }); app. Map(“/endpoint”, (app) => { app. Run( (context) => { //TODO }); app. Run( (context)=> { /* TODO */ }); public class Conventional. Middleware { private readonly Request. Delegate _next; public Conventional. Middleware (Request. Delegate next) { _next = next; } public async Task Invoke. Async (Http. Context context) { //TODO: await _next(context); } } app. Use. Middleware<Conventional. Middleware>(); public class Factory. Activated. Middleware : IMiddleware { public async Task Invoke. Async (Http. Context context, Request. Delegate next) { //TODO: await next(context); } } // register services. Add. Transient<Factory. Activated. Middle ware>(); // apply middleware app. Use. Middleware<Factory. Activated. Middlewar e>();

上下文(context) - 指引方向的北极星 • Middleware中直接使用(参数�入) • 通�注入依� IHttp. Context. Accessor • 前提:services. Add. Http.

上下文(context) - 指引方向的北极星 • Middleware中直接使用(参数�入) • 通�注入依� IHttp. Context. Accessor • 前提:services. Add. Http. Context. Accessor();

MVC全景� Dependency Injection request Model binding Router response Model Controller Format response View (Razor)

MVC全景� Dependency Injection request Model binding Router response Model Controller Format response View (Razor) View. Component

安全退出(Graceful shutdown) Microsoft. Asp. Net. Core. Hosting. IApplication. Lifetime

安全退出(Graceful shutdown) Microsoft. Asp. Net. Core. Hosting. IApplication. Lifetime