private static bool CanDecorate(ServiceRegistration registration, IAspectConfiguration aspectConfiguration)
        {
            var serviceType = registration.ServiceType.GetTypeInfo();
            var implType    = registration.GetImplType().GetTypeInfo();

            if (implType.IsProxy() || !implType.CanInherited())
            {
                return(false);
            }
            if (_excepts.Any(x => implType.Name.Matches(x)) || _excepts.Any(x => implType.Namespace.Matches(x)))
            {
                return(false);
            }
            if (!serviceType.CanInherited() || serviceType.IsNonAspect())
            {
                return(false);
            }

            var aspectValidator = new AspectValidatorBuilder(aspectConfiguration).Build();

            if (!aspectValidator.Validate(serviceType, true) && !aspectValidator.Validate(implType, false))
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        private static bool CanDecorate(ServiceRegistration registration, IAspectValidator aspectValidator, IServiceFactory factory)
        {
            var serviceType = registration.ServiceType.GetTypeInfo();
            var implType    = registration.GetImplType(factory).GetTypeInfo();

            if (implType.IsProxy() || !implType.CanInherited())
            {
                return(false);
            }
            if (_excepts.Any(x => implType.Name.Matches(x)) ||
                implType.Namespace != null && _excepts.Any(x => implType.Namespace.Matches(x)))
            {
                return(false);
            }
            if (!serviceType.CanInherited() || serviceType.IsNonAspect())
            {
                return(false);
            }

            if (!aspectValidator.Validate(serviceType, true) && !aspectValidator.Validate(implType, false))
            {
                return(false);
            }
            return(true);
        }
        private static Type CreateProxyType(IServiceFactory factory, ServiceRegistration registration)
        {
            var serviceType        = registration.ServiceType.GetTypeInfo();
            var implType           = registration.GetImplType();
            var proxyTypeGenerator = factory.GetInstance <IProxyTypeGenerator>();

            if (serviceType.IsClass)
            {
                return(proxyTypeGenerator.CreateClassProxyType(serviceType, implType));
            }
            else if (serviceType.IsGenericTypeDefinition)
            {
                return(proxyTypeGenerator.CreateClassProxyType(implType, implType));
            }
            else
            {
                return(proxyTypeGenerator.CreateInterfaceProxyType(serviceType, implType));
            }
        }