Suggestion: utility methods to create interceptors or even intercepted objects
To provide a simple interceptor like logging start/finish of all methods, users could use a utility method (lightweight) instead of being required to create a class (medium weight for a simple concern).
Example (typed from phone, so pseudo code):
IEquatable<string> sample = EqualityComparer<string>.Default;
// sample name stolen from Rx, if/when implementing spend more time naming
var wrapped = DelegateAsyncInterceptor
.Intercept<IEquatable<string>>(
target: sample,
filter: invocation => true, // optional parameter
beforeInvoke: async () => {}, // Log
afterInvoke: async () => {}); // Log
Or at least
IEquatable<string> sample = EqualityComparer<string>.Default;
// sample name stolen from Rx, if/when implementing spend more time naming
var wrapped = DelegateAsyncInterceptor
.Intercept<IEquatable<string>>(
target: sample,
interceptor:
async (invocation, proceed) =>
{
// TODO: logging
await proceed(invocation);
});
I guess the second should’ve been an example of creating a dynamic Interceptor rather than the target :) oh well the idea should be explained well enough.
It's a great idea. Maybe as an extension method to IProxyGenerator so something like this:
IEquatable<string> sample = EqualityComparer<string>.Default;
// sample name stolen from Rx, if/when implementing spend more time naming
var generator = new ProxyGenerator();
generator..Intercept<IEquatable<string>>(
target: sample,
filter: invocation => true, // optional parameter
beforeInvoke: async () => {}, // Log
afterInvoke: async () => {}); // Log
@JSkimming looking for executive decision - as a case could be made for either option...
- Add to this code base. PRO: discoverability. CON: feature-creep and more to maintain
- Leave for an external code base. (pro/con opposite of 1. CON: might not ever get done if I forget about it again like last year :) )
@ndrwrbgs I'm happy for it to be added here.