AopProxyFactory class final
Knows how to wrap one bean class in its generated proxy class, and which of its members can be advised.
Dart cannot create classes at runtime, so the generator writes a proxy
class for each bean class and attaches one of these factories to the
bean definition (its aopProxy field). When the context starts, the
AspectAutoProxyCreator asks it which advisors match the bean and has
it create the proxy. There are three forms: a wrapper class that
implements the bean's class or interfaces and forwards to it (the main
constructor), a generated subclass the bean is created as
(AopProxyFactory.subclass), and a placeholder for beans that cannot be
proxied (AopProxyFactory.unavailable). Applications do not create it;
ProxyFactory.forBean uses it to make more proxies of a bean.
Unlike Spring's JDK and CGLIB proxies, the proxy class is written at build time, so no reflection is needed at runtime.
// In a test, with a proxy class CalculatorProxy written by hand:
// wrap a SimpleCalculator so every call is logged.
final factory = AopProxyFactory(
signatures: CalculatorProxy.signatures,
create: (target, invoker) =>
CalculatorProxy(target as SimpleCalculator, invoker),
);
final Calculator proxy = factory.createProxy(
SimpleCalculator(),
[DefaultPointcutAdvisor(const TruePointcut(), LoggingInterceptor())],
) as Calculator;
Spring (Java):
ProxyFactory factory = new ProxyFactory(new SimpleCalculator());
factory.addAdvisor(
new DefaultPointcutAdvisor(Pointcut.TRUE, new LoggingInterceptor()));
Calculator proxy = (Calculator) factory.getProxy();
Constructors
-
AopProxyFactory({required List<
MethodSignature> signatures, required Object create(Object target, ProxyInvoker invoker), List<Introduction> introductions = const []}) -
A factory for a wrapper proxy class whose advisable members are
signatures;createinstantiates the generated class around a target. - AopProxyFactory.pruned({required String reason})
-
A bean the build gave no proxy class: no pointcut it knows of matches
the bean (
reasonsays so). Nothing is generated for its members, so advice registered at run time without the build seeing it (an advisor bean added by hand to a context) is not applied to it; build with the optionaop_prune: falseto keep every proxy.const -
AopProxyFactory.subclass({required List<
MethodSignature> signatures, required Object? advise(Object bean, ProxyInvoker invoker), List<Introduction> introductions = const []}) - A factory for a bean whose class cannot be implemented but can be extended, which the container creates as a generated subclass.
-
A placeholder for a bean whose class cannot be proxied, with the
reason.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
introductions
→ List<
Introduction> -
The interfaces the proxy class implements for
@DeclareParents; the proxy refers to each by its index in ProxyInvoker.introduction.final - isSubclass → bool
-
Whether the bean is created as a generated subclass that advice is
attached to, instead of being wrapped.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
signatures
→ List<
MethodSignature> -
The bean's advisable members; the generated proxy refers to each by
its index in this list.
final
-
Why the bean cannot be proxied;
nullwhen it can.final
Methods
-
createProxy(
Object target, List< PointcutAdvisor> advisors, {String beanName = '', List<String> beanAliases = const []}) → Object -
Returns the proxy of
targetthat runsadvisors, outermost first. -
eligibleAdvisors(
List< PointcutAdvisor> advisors, String beanName, {List<String> beanAliases = const []}) → List<PointcutAdvisor> -
The advisors among
advisorsthat match at least one member of the bean namedbeanName, in their order.beanAliases(the bean's aliases and qualifier values) also count forbean(...)pointcuts. An empty result means the bean needs no proxy. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited