Allowing injecting in constructor's (#30 #40)

* Allowing injecting in constructor

It is bad to assume that everyone does business logic outside of constructor. We don't want redirect conflict hell

* This should work

Signed-off-by: liach <[email protected]>

* Add notes for easy portin in the future

Signed-off-by: liach <[email protected]>

* Restore build number

* Adopt new versioning scheme

Signed-off-by: liach <[email protected]>

Co-authored-by: liach <[email protected]>
Co-authored-by: liach <[email protected]>
This commit is contained in:
authored and GitHub committed 2020-10-26 20:07:59 +00:00
1 parent 279f1e6957
commit 536170a946
2 files changed
+23

No files matched your search

@@ -289,6 +289,19 @@ public abstract class InjectionPoint {
* @return restriction level
*/
public RestrictTargetLevel getTargetRestriction(IInjectionPointContext context) {
return RestrictTargetLevel.CONSTRUCTORS_AFTER_DELEGATE; // Fabric change: allow inject in constructors
}
/**
* Returns the target restriction level for this injection point's cancellation for
* {@literal @Inject} annotations. This level defines whether an injection point
* can declare {@code cancellable = true}.
*
* @param context injection-specific context
* @return restriction level
*/
// Fabric addition: prevent cancellation of inject in constructors
public RestrictTargetLevel getCancellationRestriction(IInjectionPointContext context) {
return RestrictTargetLevel.METHODS_ONLY;
}
@@ -397,6 +397,16 @@ public class CallbackInjector extends Injector {
throw new InvalidInjectionException(this.info, String.format("%s selector %s", ip, ex.getMessage()));
}
// Fabric start: prevent cancellation in constructor injections
if (this.cancellable) {
try {
this.checkTargetForNode(target, injectionNode, ip.getCancellationRestriction(this.info));
} catch (InvalidInjectionException ex) {
throw new InvalidInjectionException(this.info, String.format("%s selector (cancellable = true) %s", ip, ex.getMessage()));
}
}
// Fabric end
String id = ip.getId();
if (Strings.isNullOrEmpty(id)) {
continue;