-
Notifications
You must be signed in to change notification settings - Fork 470
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
Support collectible assemblies via new CollectibleProxyBuilder
#685
base: master
Are you sure you want to change the base?
Support collectible assemblies via new CollectibleProxyBuilder
#685
Conversation
617627e
to
42dfbc7
Compare
CollectibleProxyBuilder
CollectibleProxyBuilder
@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. |
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 ? |
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.