触手游戏下载,海鲎,麻辣女兵演员表
aspectcore project 介绍
aspectcore project 是适用于asp.net core 平台的轻量级 aop(aspect-oriented programming) 解决方案,它更好的遵循asp.net core的模块化开发理念,使用aspectcore可以更容易构建低耦合、易扩展的web应用程序。
在传统.net framework和asp.net framework中,我们使用castle dynamicproxy 或者clr提供的 remoting.proxies 可以轻松的实现 aop 来分离关注点从而降低业务逻辑和基础框架功能的耦合。然而在asp.net core中,不仅缺乏细粒度的aop支持(middleware
和filter
都是asp.net core的内置aop实现,但仅适合在web层使用),castle也迟迟未能友好的支持asp.net core。
因此 aspectcore 提供了一个全新的轻量级和模块化的aop解决方案,下面是aspectcore的基本特性:
service
的而非基于实现类的切面构造上面是一些概念介绍,关于aop指的是面向切面编辑,其时我们之前用过,只是没注意而已,比如.netcore中的services中的方法,注入到服务中,权限过滤等都可以理解为aop.
下面使用aspectcore写一个注入的例子,可以应用到验证权限中。
using aspectcore.dynamicproxy; using system; using system.collections.generic; using system.linq; using system.threading.tasks; namespace aspectcore { public class custominterceptorattribute: abstractinterceptorattribute { public async override task invoke(aspectcontext context, aspectdelegate next) { try { console.writeline("before service call"); await next(context); } catch (exception) { console.writeline("service threw an exception!"); throw; } finally { console.writeline("after service call"); } } } }
using aspectcore.dynamicproxy; using system; using system.collections.generic; using system.linq; using system.threading.tasks; namespace aspectcore.services { public interface icustomservice { [custominterceptor] void call(); } public class customservice : icustomservice { public void call() { console.writeline("service calling..."); } } }
using system; using system.collections.generic; using system.linq; using system.threading.tasks; using aspectcore.services; using microsoft.aspnetcore.http; using microsoft.aspnetcore.mvc; namespace aspectcore.controllers { [route("api/[controller]")] [apicontroller] public class homecontroller : controllerbase { private readonly icustomservice _service; public homecontroller(icustomservice service) { _service = service; } [httpget("getmsg")] public void getmsg() { _service.call(); } } }
using system; using aspectcore.configuration; using aspectcore.extensions.dependencyinjection; using aspectcore.injector; using aspectcore.services; using microsoft.aspnetcore.builder; using microsoft.aspnetcore.hosting; using microsoft.aspnetcore.mvc; using microsoft.extensions.configuration; using microsoft.extensions.dependencyinjection; namespace aspectcore { public class startup { public startup(iconfiguration configuration) { configuration = configuration; } public iconfiguration configuration { get; } // this method gets called by the runtime. use this method to add services to the container. public iserviceprovider configureservices(iservicecollection services) { //根据属性注入来配置全局拦截器 services.configuredynamicproxy(config => { config.interceptors.addtyped<custominterceptorattribute>();//custominterceptorattribute这个是需要全局拦截的拦截器 }); services.addmvc().setcompatibilityversion(compatibilityversion.version_2_1); ; services.addsingleton<icustomservice, customservice>(); var servicecontainer = services.toservicecontainer();//容器 return servicecontainer.build(); } public void configure(iapplicationbuilder app, ihostingenvironment env) { if (env.isdevelopment()) { app.usedeveloperexceptionpage(); } else { app.usehsts(); } app.usehttpsredirection(); app.usemvc(); } } }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论