Closed amoraller closed 2 years ago
@amoraller Can you please describe your scenario, proxying a proxy is not something I'd recommend.
@jonorossi i want add interface and implementation for existing object at runtime. I have data source with IObservable<byte[]> implementation and i need create plugins for my app. Any plugin can modify behavior (with interceptor) or add interface implementation.
For example my usb device produced byte[] data, and plugins inspect specific data and send answer to device. User can enable plugin at runtime.
Sometime i use this code
public static IPrizrakDevice CreateDecorator(IPrizrakDevice @internal)
{
var stateSaver = new QueuePrizrakDeviceImpl(@internal);
var options = new ProxyGenerationOptions();
options.AddMixinInstance(stateSaver);
Type[] interfaces = ProxyHelper.GetInterfaces(@internal);
var proxy = pg.CreateInterfaceProxyWithTargetInterface(typeof(IPrizrakDevice), interfaces, @internal, options);
return proxy as IPrizrakDevice;
}
public static Type[] GetInterfaces(object source)
{
IEnumerable<Type> interfaces = source.GetType().GetInterfaces();
if (ProxyUtil.IsProxy(source))
{
interfaces = interfaces.Where(p => p != typeof(IProxyTargetAccessor));
}
return interfaces.ToArray();
}
As a workaround i want use Fluent Builder pattern or use Dictionary with behaviour extensions.
Hi.
Why i can not create proxy of proxy using mixins?
If i create second proxy i catch exeption