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

Make most of DynamicProxy's internals internal #505

Merged
merged 4 commits into from
Jun 8, 2020

Conversation

stakx
Copy link
Member

@stakx stakx commented Jun 6, 2020

We've been talking about making internals truly internal (see e.g. #389) so that we can more easily refactor in the future. This PR is my initial attempt at doing so for DynamicProxy.

What this PR does not do is change type names or namespaces. The latter might make sense in some cases (e.g. moving AttributesToAvoidReplicating into DynamicProxy's main namespace Castle.DynamicProxy, or perhaps combining all exception types into a single DynamicProxyException type). I would personally favor such changes, but they are left to future PRs.

Compatiblity checks for downstream libraries

Windsor

Windsor will be able to update without any major changes. Those are the main required changes that I have identified:

  • Its single use of DelegateProxyGenerator will have to be replaced with ProxyGenerationOptions.AddDelegateTypeMixin. This is straightforward, as demonstrated in the unit tests in one of this PR's commits.

  • (Unrelated to this PR, but since we're discussing Windsor:) It makes use of the Lock APIs in approx. 15 places. The easiest solution would be to migrate the Lock API over into Windsor from an older version of Castle.Core (but make it internal). The slightly more laborious solution would be to change all Lock usages to use ReaderWriterLockSlim directly. (This latter approach is definitely possible, but not as straightforward as it may seem because the Lock API implements some kind of reentrancy on top of non-reentrant ReaderWriterLockSlim instances.)

  • (Unrelated to this PR:) Windsor targets some frameworks that we no longer support here (e.g. net40), those will have to be dropped.

FakeItEasy, Moq 4, and NSubstitute

The API removals do not cause any problems for these three libraries. (I've checked by compiling them against this PR's version of Castle.Core. The only problem is unrelated to this PR—some of these libraries will only be able to update after removing their netstandard1.x targets, which we stopped supporting in #495.)

stakx added 4 commits June 5, 2020 22:38
This consists mostly of making `public` types in the `Castle.Dynamic-
Proxy` namespace `internal`, however there are a few special cases
where types are left public but some or most of their members are made
internal, for example:

 * exception types (client code should be able to catch them, but not
   instantiate them)

 * `TypeUtil` (proxies require some of its members at runtime)

 * `ModuleScope` (`SaveAssembly`, `LoadAssemblyIntoCache`, and related
   members should stay public for now, unlike others that give access
   to the internal `ModuleBuilder`)
 * Windsor needs `TypeUtil.GetAllInterfaces`, so make it public again.

 * Windsor is currently relying on `DelegateProxyGenerator`, but there
   is now another, more public API to build delegate proxies (see PR
   castleproject#436) so that class can
   now be removed. The unit tests for it are rewritten in terms of the
   newer API to demonstrate that it is indeed a suitable replacement.
It is no longer feasible to list every single affected type or type
member; there's simply too many. Give a coarse summary instead.
Copy link
Member

@jonorossi jonorossi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@jonorossi jonorossi merged commit 7b27705 into castleproject:master Jun 8, 2020
@stakx stakx deleted the dynamicproxy-internals branch June 8, 2020 08:27
@jonorossi jonorossi added this to the v5.0.0 milestone Jun 8, 2020
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

Successfully merging this pull request may close these issues.

2 participants