Proxy Support
jbee opened this issue · 2 comments
Edit: Solution can be done by users, see last comment.
In contrast to many dependency injection containers we do not create proxies for injected interfaces by default or at all. A ProxyFactory
concept should make it easier for the user to add a user defined proxy for:
- a selected set of interfaces, or
- interfaces extending a "Proxied" base interface
Users could use existing bindings to manually create such an outcome.
A proxied interface would need to be bound to a supplier that internally resolves the implementation and wraps it with the proxy. This is kind of unhandy especially on the binding end and can get confusing easily in case of more complicated bindings.
interface ProxyFactory {
<T> T newProxy(Type<T> proxied, T impl);
}
As usual a general mechanism that makes it easier to get in-between usual resolution might be the better feature to add.
This can be implemented by wrapping the Injector
and returning proxies from the wrapping injector. This also needs to update the generator
field of Resource
s to have the same behaviour.
Another (most likely better) method is to use an Initialieser<Object>
with a contract filter so it applies only to interface resources which returns the proxy from the initialiser. This should be used in connection with a Sorter
to make sure the proxy initialiser is the last applied.