Closed jbee closed 9 years ago
Interceptor
s should be something that could make use of extension points.
It is always about a set of classes. Sometimes there is a constraint that all should extend a base-type. Maybe this could be done more like Bundle
s and Module
s. Something like the service-classes is a Extension
s.
The benefit of a Class
based extension is that an extension is defined by a consumer and used by several contributors. This can be understood by the bootstrapper whereby contributions to not installed extensions will not even make their way into a binding.
Most likely it will be wise to use enums here too. While Extension
is an interface implemented by them.
enum ServiceMethodExtension implements Extension<Object> { }
Here the generic is Object
because there is no limitation what classes could be used. In case of a Interceptor
it would be
enum ServiceMethodInterceptorExtension implements Extension<Interceptor> { }
Via reflection the type argument on Extension
can be read. No further methods are necessary.
The constants of the enum can be used to allow groups of something like here e.g. Interceptor
s used before and others used after. When no groups are needed just one constant is used. When add an actual extension class just the enum class is an alias to the first constant.
extend(ServiceMethodInterceptorExtension.class, LoggingInterceptor.class);
//or
extend(ServiceMethodInterceptorExtension.BEFORE, LoggingInterceptor.class);
It should be possible to narrow down when to use a extension (packages, types - same as binds in general). Maybe it works already ?!
finally plug
-into
has solved this nicely. (v0.8)
ExtensionPoint as a set of uniform values - all of them arise from binds. Something like this is used for service classes.
The extension point should allow to handle those kind of need better and more independent from the builder. the builder gets convenient support for ExtensionPoints. A user can always add more of those points.
The example shows that a point could be a constant having a id
String
and a element type. The usage could look like this:So the signature of the above method looks like
Or for better encapsulation the point has methods that accept a
Binder
When loading all bound elements it could look like:
Like this the class becomes a nice util.