Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to register using explicit types rather than bean.getClass() canonical name #97

Closed
rbygrave opened this issue May 10, 2021 · 0 comments
Assignees
Milestone

Comments

@rbygrave
Copy link
Contributor

The issue is with @Factory @Bean methods. These can return anonymous classes or real classes and we can get subtle behaviour here.

This change removes the use of bean.getClass() when registering and changes to explicit types.

  @Bean
  @Named("BuildDesi1")
  DesEngi buildEngi() {
    methods += "|buildEngi1";
    return new DesEngi(){
      @Override
      public String ignite() {
        return "buildEngi1";
      }
    };
  }

  @Bean
  @Named("BuildDesi2")
  DesEngi buildEngi2() {
    methods += "|buildEngi2";
    return new MyEngi();
  }

With current generated code explicitly registering both DesEngi.class, Engi.class types.

  /**
   * Create and register DesEngi via factory bean method MyFactory#buildEngi().
   */
  public static void build_buildEngi(Builder builder) {
    if (builder.isAddBeanFor("BuildDesi1", DesEngi.class, Engi.class)) {
      MyFactory factory = builder.get(MyFactory.class);
      DesEngi bean = factory.buildEngi();
      builder.register(bean, "BuildDesi1", DesEngi.class, Engi.class);
    }
  }

  /**
   * Create and register DesEngi via factory bean method MyFactory#buildEngi2().
   */
  public static void build_buildEngi2(Builder builder) {
    if (builder.isAddBeanFor("BuildDesi2", DesEngi.class, Engi.class)) {
      MyFactory factory = builder.get(MyFactory.class);
      DesEngi bean = factory.buildEngi2();
      builder.register(bean, "BuildDesi2", DesEngi.class, Engi.class);
    }
  }
@rbygrave rbygrave self-assigned this May 10, 2021
@rbygrave rbygrave added this to the 3.3 milestone May 10, 2021
rbygrave added a commit that referenced this issue May 11, 2021
…lass() canonical name

Plus
- #96 Case insensitive qualifier names
- #98 Support @singleton that extends another concrete @singleton
rbygrave added a commit that referenced this issue May 11, 2021
This means we only declare the qualifier and types once in generated code which makes more sense
rbygrave added a commit that referenced this issue May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant