ThorbenKuck / ThorbenKuck/WireDI

[Feature]: Add "Compile Time" and "Runtime" lifecycle scopes

Open
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request priority-low
Dominant language
Java
Stars
6
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Type of feature request

A completely New Feature

What kind of feature would you like to see

The annotation processor can, in a lot of situations generate code that is kind of "pre-compiled".

For example: If you have any dependencies in a method annotated with @Aspect, the annotation processor will generate an instance of the AspectHandler interface and declare these as constructor parameters, hence declaring them as required parameters.

In contrast to that, you might be tempted to not have them as a constructor parameter, but fetch them from the WireRepository lazily and on demand.

This can be used, if classes are commonly exchanged in the BeanContainer during runtime.

Code Examples
public class MyHandler {
    @Aspect(around = Example.class)
    @LifecycleScope(COMPILE)
    public Object handle(ExecutionContext<Example> context, MyService myService) {
        // ...
    }
}

Will compile to:

@Wire
@Generated
public final class MyHandler$handle$AspectHandler implements AspectHandler<Example> {
   private final MyHandler delegate;
   private final MyService myService;

   protected TransactionalHandler$handle$AspectHandler(
                MyHandler delegate,
                MyService myService
    ) {
      this.delegate = delegate;
      this.myService = myService;
   }

   @Override
   @Nullable
   public final Object process(@NotNull final ExecutionContext<Transactional> context) {
      return delegate.handle(
               context,
               myService
            );
   }
}

whilst

public class MyHandler {
    @Aspect(around = Example.class)
    @LifecycleScope(RUNTIME)
    public Object handle(ExecutionContext<Example> context, MyService myService) {
        // ...
    }
}

Will compile to:

@Wire
@Generated
public final class MyHandler$handle$AspectHandler implements AspectHandler<Example> {
   private final MyHandler delegate;
   private final WireRepository wireRepository;

   protected TransactionalHandler$handle$AspectHandler(
                MyHandler delegate,
                WireRepository wireRepository
    ) {
      this.delegate = delegate;
      this.wireRepository = wireRepository;
   }

   @Override
   @Nullable
   public final Object process(@NotNull final ExecutionContext<Transactional> context) {
      return delegate.handle(
               context,
               wireRepository.require(MyService.class) // fetch the dependency on demand
            );
   }
}
Feature Design

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the annotation processor and the existing @Aspect handling, then trace how dependencies become generated constructor parameters. Compare the requested COMPILE and RUNTIME behavior, including lazy WireRepository lookup for runtime dependencies. Done means @LifecycleScope supports both scopes and generated handlers match the examples without breaking existing aspect processing.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.