Skip to content

Instantly share code, notes, and snippets.

How to not screw up IC

From the perspective of somebody who actually did

These days have drained us all:

  • Show you've got traction.
  • Build your narrative.
  • Practice your pyramids!

The reality is that you need to expect the unexpected, so here are my three top tips to not screw up IC (because in hindsight, everything is simpler!).

MyFramework framework = MyFramework.builder()
.optionA(…)
.optionB(…)
.set("optionName", …)
.build();
framework.init(…);
Map<String, Object> config = loadConfig();
MyFramework.Builder builder = MyFramework.builder();
config.forEach((key, value) -> builder.set(key,value));
MyFramework framework = builder.build();
public ScanContext scan(Object instance, ScanOptions options) {
return scan(instance, options, new ScanContext(), new ArrayList<?>());
}
public interface AnnotationHandler<T extends Annotation> {
void handle(ScanContext scanContext, FrameworkAnnotationContext<T> annotationContext);
}
@Getter
@AllArgsConstructor
public class FrameworkAnnotationContext<T extends Annotation> {
private T annotation;
private Object instance;
private AnnotatedElement annotatedElement;
}
@Target(ElementType.ANNOTATION_TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Handler {
Class<? extends AnnotationHandler> value();
}
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Handler(MyAnnotationHandler.class) // ← link to the handler
public @interface MyAnnotation {
String foo();
String bar();
}
public class MyAnnotationHandler implements AnnotationHandler<MyAnnotation> {
@Override
public void handle(ScanContext scanContext, FrameworkAnnotationContext<MyAnnotation> annotationContext) {
System.out.println("Foo is " + annotationContext.getAnnotation().foo());
System.out.println("Bar is " + annotationContext.getAnnotation().bar());
}
}
public class GetMappingHandler implements AnnotationHandler<GetMapping> {
@Override
public void handle(ScanContext scanContext, FrameworkAnnotationContext<GetMapping> annotationContext) {
String endpoint = annotationContext.getAnnotation().value();
Method m = (Method) annotationContext.getAnnotatedElement();
Object o = annotationContext.getInstance();
scanContext.createMapping(endpoint, m, o);
}
}