Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Decorators are a cheap alternative to AOP in DI. They have an advantage of being plain Java code (have you ever seen typical AOP interceptors ... insane unreadable mess) and having good performance (reading a ResultSet using a proxy-based strategy is going to be painful). So adding this simple construct that can be used in DI modules:
binder.bind(I1.class).to(C1.class); binder.decorate(I1.class).after(D1.class).before(D2.class);
Each decorator declares access to a decorated "delegate" using normal @Inject annotation either in constructor or via a field. As mentioned before, a decorator is simply a class implementing a given interface. Very clean.