我将采用 https://github.com/vescon/MethodBoundaryAspect.Fody 作为我的 AOP 引擎。但是,由于它是编译时方法,因此我在如何从 IServiceCollection/DI 检索服务方面遇到问题。
如有任何建议,我们将不胜感激。预先感谢
这确实是可能的。
我目前正在一个 WinUI 项目中工作,我执行以下操作:
public sealed class MyAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
IMyService myService = App.GetService<IMyService>();
if (myService.DoSomething())
{
// ...
args.FlowBehavior = FlowBehavior.Return;
}
}
}