pamidur / aspect-injector

AOP framework for .NET (c#, vb, etc)
Apache License 2.0
745 stars 112 forks source link

Multiple Aspect On Method #119

Closed murseld closed 2 years ago

murseld commented 4 years ago

Hello pamidur and me again :)

When I want to use multiple aspect for example CacheAspect and LogAspect, CacheAspect (if cache contains any data) prevents the other LogAspect from using the Kind.After property because log aspect is logging when method is complete.

How can I avoid this do you have any advice. Thank you my friend..

[LogAspect(typeof(NLogManager))] [CacheAspect(typeof(RedisCacheManager), 15)] public User Get(int? key) { return _userDal.Get(p => p.UserId == key); }

CacheAspect.txt LogAspect.txt

pamidur commented 4 years ago

Hi @murseld , Aspect with Kind.Around effectively override any other kind. But you can use multiple Kind.Around aspects. Don't forget to set Injection.Priority

For these to work you need to implement all of yours concurrent aspects as Kind.Around.

I'll leave this issue opened as I think I could come up with how to make priorities "cross-kind" e.g. make all Before and After as part of another internal Around.

pamidur commented 4 years ago

Hey @murseld , I have recently implemented Cache aspect. Could you please take a look and see if it can suit your needs? https://github.com/pamidur/aspect-injector/tree/master/samples/src/Cache

I'm asking as you're the one with real cache problem need to solve. Would be great if you take a look :)

murseld commented 4 years ago

Hi pamidur it was great. thank you very much...

pamidur commented 4 years ago

Hi @murseld , I've created new prerelease 2.4.0-beta1. I changed weavers priority in it. So Before/After are always injected even when other aspect with Around is used. You may try it!

pamidur commented 2 years ago

Should be fixed now. Please feel free to reopen