Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can MethodBoundaryAspect.Fody be used to apply aspects to third-party NuGet packages without modifying their source code? #117

Open
InCerryGit opened this issue Jul 1, 2023 · 2 comments

Comments

@InCerryGit
Copy link

Hi,

I have a project A that depends on a third-party NuGet package B. I cannot modify the source code of package B. There's a method called MethodA inside package B, and I would like to apply AOP aspects using MethodBoundaryAspect.Fody to this method without altering the project A.

Is it possible to achieve this using MethodBoundaryAspect.Fody? If so, could you please provide some guidance or examples on how to implement this?

Thank you.

@Ralf1108
Copy link
Collaborator

Ralf1108 commented Jul 4, 2023

Hi,

through the built-in mechanism of Fody it is not possible. Fody runs as an additional build step after compilation so you would need the source code to use it.
First source code is compiled to an assembly and then Fody invokes the configured weavers and provide the assembly with it.

So the weaving logic won't care if the assembly is fresh compiled or if it already existed before.
The difference is that you have to start the weaving process via you own way.

As Fody is using "Mono.Cecil" under the hood please google it. It is just a .Net library for parsing and modifying assemblies.
When get it running you can just invoke the entrance weaver class by yourself with the appropriate properties set.

As your assembly is already compiled how will you mark the methods which should be weaved? Normaly this is done via adding .Net attributes in the source code.
But you can change method discovery mechanism in the weaver code also, e.g. hard code method names/namespaces.

Please keep us updated and maybe show your solution. Maybe others are also interested in this and it leads to an own project :-)

@Ralf1108
Copy link
Collaborator

Ralf1108 commented Jul 4, 2023

Place where methods to weave are selected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants