Рекомендуемый способ использования перехвата в DryIoc больше не работает с версии 3.0:
https://bitbucket.org/dadhi/dryioc/wiki/Interception
Метод GetPublicInstanceConstructors отсутствует. Каким новым способом добиться этого?
Рекомендуемый способ использования перехвата в DryIoc больше не работает с версии 3.0:
https://bitbucket.org/dadhi/dryioc/wiki/Interception
Метод GetPublicInstanceConstructors отсутствует. Каким новым способом добиться этого?
Made.Of((Type type) => type.GetConstructors().SingleOrDefault(c => c.GetParameters().Length != 0)
Кажется, работает.
Вот рабочий код интеграции ( который, вероятно, в будущем будет перенесен в отдельный пакет):
using System;
using Castle.DynamicProxy;
using ImTools;
namespace DryIoc.Interception
{
// Extension methods for interceptor registration using Castle Dynamic Proxy.
public static class DryIocInterception
{
public static void Intercept<TService, TInterceptor>(this IRegistrator registrator, object serviceKey = null)
where TInterceptor : class, IInterceptor =>
registrator.Intercept<TInterceptor>(typeof(TService), serviceKey);
public static void Intercept<TInterceptor>(this IRegistrator registrator, Type serviceType, object serviceKey = null)
where TInterceptor : class, IInterceptor =>
registrator.Intercept(serviceType, Parameters.Of.Type(typeof(IInterceptor[]), typeof(TInterceptor[])), serviceKey);
public static void Intercept(this IRegistrator registrator,
Type serviceType, ParameterSelector interceptorsParameterSelector, object serviceKey = null)
{
Type proxyType;
if (serviceType.IsInterface())
proxyType = ProxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(
serviceType, ArrayTools.Empty<Type>(), ProxyGenerationOptions.Default);
else if (serviceType.IsClass())
proxyType = ProxyBuilder.CreateClassProxyTypeWithTarget(
serviceType, ArrayTools.Empty<Type>(), ProxyGenerationOptions.Default);
else
throw new ArgumentException(
$"Intercepted service type {serviceType} is not a supported, cause it is nor a class nor an interface");
registrator.Register(serviceType, proxyType,
made: Made.Of(
pt => pt.PublicConstructors().FindFirst(ctor => ctor.GetParameters().Length != 0),
interceptorsParameterSelector),
setup: Setup.DecoratorOf(useDecorateeReuse: true, decorateeServiceKey: serviceKey));
}
private static DefaultProxyBuilder ProxyBuilder => _proxyBuilder ?? (_proxyBuilder = new DefaultProxyBuilder());
private static DefaultProxyBuilder _proxyBuilder;
}
}