inversionhourglass / Rougamo

Compile-time AOP component. Works with any method, whether it is async or sync, instance or static. Uses an aspectj-like pattern to match methods.
MIT License
393 stars 47 forks source link

MoAttribute 怎么解析Ioc服务呢? #33

Closed 18682788952 closed 1 year ago

inversionhourglass commented 1 year ago

如果是想要在MoAttribute里使用一些动态配置,可以参考 https://github.com/inversionhourglass/Rougamo.OpenTelemetry/blob/master/src/Rougamo.OpenTelemetry.Hosting/Microsoft/Extensions/DependencyInjection/RougamoOtelHostingExtensions.cs 。如果是想要更灵活在MoAttribute中通过ioc获取对象实例,可以参考 https://freesql.net/guide/unitofwork-manager.html#%E7%AC%AC%E4%BA%8C%E6%AD%A5-%E9%85%8D%E7%BD%AE-startup-cs-%E6%B3%A8%E5%85%A5%E3%80%81%E4%B8%AD%E9%97%B4%E4%BB%B6

由于rougamo是静态织入,所以没有特别便捷的方式接入ioc,主要的交互方式就是通过静态变量进行交互

2881099 commented 8 months ago

最近接触 blazor SSR,使用 AsyncLocal 的方式不再凑效了。

blazor SSR 的特点是长连接,ioc Scoped 正常使用没问题。

但 AsyncLocal 在这种模式下很容易丢失上下文,原因是长链接各种异步 UI 操作,一言难尽。

希望肉夹馍出一个指定传入 IServiceProvider 的方式。