-
Notifications
You must be signed in to change notification settings - Fork 483
Support collectible assemblies via new CollectibleProxyBuilder
#685
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
base: master
Are you sure you want to change the base?
Support collectible assemblies via new CollectibleProxyBuilder
#685
Conversation
617627e to
42dfbc7
Compare
CollectibleProxyBuilderCollectibleProxyBuilder
|
@castleproject/committers, I'll let this PR sit for a few days, in case anyone wants to review. If there are no objections, I'll go ahead and merge it in a few days' time as the enhancement to DynamicProxy it contains is fairly trivial. |
jonorossi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stakx Looks good. Could we add a very basic unit test to ensure the this new proxy builder at least works?
|
Thanks for reviewing. You're right, I forgot to write a test, since this started out only as a proof of concept. I'll add one. |
|
Hi @stakx, I have some reserve about this approach as it will require all moqing frameworks to opt-into leverage this to be able to work without leaking Assembly Load Contexts in environments that leverage them. The example of Unity 7 where we are moving to CoreCLR and take advantage of ALCs (AssemblyLoadContext) to allow users to iterate on their code without reloading the editor:
If any non-unloadable ALC keep references to anything loaded within the User ALC, the unload will never complete (the GC will see outstanding references to some objects belonging to that ALC and thus will keep it alive). We call that ALC leaks in Unity. With that PR, if a Moqing framework relying on Castle.Core wants to play nice with Unity (or any other environment that does leverage unloadable ALCs), it will need to explicitly opt-into using this new CollectibleProxyBuilder. I don't think it is the responsibility of the Moqing framework, but more about the hosting process to decide in which kind of ALC generated code should get loaded: that is why I first introduced a global static setting that a runtime environment could use to define this behavior (e.g. if Unity detects that Castle.Core is loaded, it would set the setting accordingly so that any moqing framework would generate its code in a way that plays nice with Unity runtime). So what I really think we should have to define if the builders should emit collectible types is this:
That could be implemented by having:
What would you think of that ? |
|
@simonferquel, I've decided not to answer right away because had I done so, you would have got my standard canned response: that DynamicProxy is a general-purpose library and shouldn't be opinionated (and that it's therefore really up to mocking libraries to opt-into the new After getting some distance, while I still believe the above statement to be true, I think I also see your point. DynamicProxy sometimes does try to make decisions itself so that things "just work" (e. g. when choosing whether to put generated proxy types in a strong-named or non-strong-named dynamic assembly). I am, however, still uncertain whether the auto-detection logic you originally proposed would be correct in all circumstances. (I know: you've provided a global switch to adjust it when things go wrong. I'd still prefer there to be no such global switches, if possible.) My uncertainties are based on there being several aspects to the problem space that I don't fully understand yet:
I have thought more on these, but I'll stop here for the moment. Perhaps you have some thoughts of your own regarding those questions that you'd care to share. |
This is an alternative to #679. Consider it a proof of concept that is to be discussed further, over in #473. If we went ahead with this approach, the code here might have to be cleaned up a little more.