Comments (5)
要拦截类的话,应该把方法标记为virtual
,如果是属性,也应该把属性标记为virtual
,并且拦截器特性标记在get
或set
上面,并且不应该使用 services.BuildServiceProvider()
而是使用services.BuildAspectCoreServiceProvider()
from aspectcore-framework.
AspectCore 在AspNet Core中提供可选使用MSDI的serviceProvider 和 AspectCore的serviceProvider:
- 使用MSDI的serviceProvider
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddDynamicProxy();
return services.BuildAspectCoreServiceProvider();
}
- 使用AspectCore提供的serviceProvider
public IServiceProvider ConfigureServices(IServiceCollection services)
{
var container = services.ToServiceContainer();
return container.Build();
}
from aspectcore-framework.
@liuhaoyang 请问 这两种有什么区别?
因为在微软某处demo 或者 库里面 (忘了具体的哪) 配置服务的时候这样写的
public static IServiceCollection AddExt(this IServiceCollection services)
{
var provider = services.BuildServiceProvider();
services.Configure<CookieOptions>(op=>{
// 这里的类型都是例子
op.Domain = provider.GetRequiredService<string>();
});
return services;
}
这里的 provider 应该是 微软的 Microsoft.Extensions.DependencyInjection.ServiceProvider
, 我担心是这个微软的Provider 没有 拦截效果
from aspectcore-framework.
https://github.com/dotnetcore/AspectCore-Framework/blob/master/core/src/AspectCore.Core/Configuration/Extensions/NonAspectsCollectionExtensions.cs 这里面预置了一些不会被拦截的namespace 。包括System下面的类,Microsoft.开头的类不会被拦截
from aspectcore-framework.
@liuhaoyang 你好像误会我的问题了
我是想问,如果我按上面那个 配置 CookieOptions
的方式 ”var provider = services.BuildServiceProvider();“
, 获取一个 应该拥有拦截的类, 是否这个类就失去了 拦截效果?
from aspectcore-framework.
Related Issues (20)
- .Net 6 方法参数带in修饰符的值类型参数会报null错误, in 引用类型无此问题. HOT 1
- Not working if use CreateDefaultBuilder HOT 1
- Generics interface inherit bugs in ASP.NET Core 6
- .net 7.0 报错 HOT 1
- 项目上Autofac+aspectCore做ioc容器+aop,EnableParameterAspect之后Skywalking agent无法采集数据到服务器上
- Tars.Net link from README.md returns 404 Page Not Found
- Unable to cast object of type 'AspectCore.DynamicGenerated.MySqlStorageInitializer' to type 'DotNetCore.CAP.MySql.MySqlStorageInitializer'. HOT 1
- After introducing aop and calling the RegisterDynamicProxy method, execute the program again and find an exception HOT 3
- 特性无法拦截,是没考虑到这种场景,还是根本不支持呢? HOT 1
- 同一个接口下多个方法有拦截,相互调用只有第一个拦截生效 HOT 1
- 使用aspectCore做SqlSugar的事务拦截器,发现获取ISqlSugarClient对象变了 HOT 2
- 2.3.0版本升级后,发生System.NullReferenceException异常 HOT 4
- aop 能对属性进行拦截操作吗
- Bug:使用拦截器的时候从容器获取对象时调用的构造方法错误 HOT 3
- 启动性能问题 HOT 3
- Predicates.ForService 里面获取的类不全,导致无法aop HOT 5
- Bug-Report[Construct]doesnt support Parameters HOT 1
- Net8 兼容性错误 HOT 4
- 解惑下,以下代码在实现一个接口情况下可以 aop吗 HOT 1
- 对.net8 Framework有发布计划么? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspectcore-framework.