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

Shared reference between beans? #33

Open
dirkredeye opened this issue Oct 11, 2019 · 1 comment
Open

Shared reference between beans? #33

dirkredeye opened this issue Oct 11, 2019 · 1 comment

Comments

@dirkredeye
Copy link

Hi!

I want to try this library for testing, but the immediate problem I've run into is that I can't re-use an instance. Essentially I want to do this:

pizza: &pizza
  ingredients:
    - ham
    - cheese
    - pineapple
  name: hawaiian

mario: &mario
  name: Mario
  lunch: *pizza
  dinner: *pizza
  breakfast: *pizza

Except I want a single instance of Pizza. Eg so that mario.lunch == mario.dinner instead of just mario.lunch.equals(mario.dinner)

Is there a built in way I can do this?

@dirkredeye
Copy link
Author

dirkredeye commented Oct 11, 2019

At first, I thought I could do this with a custom ScriptHandler that lets me use a function like

pizza: &pizza
  ingredients:
    - ham
    - cheese
    - pineapple
  name: hawaiian

mario: &mario
  name: Mario
  lunch: singleton(pizza)
  dinner: singleton(pizza)
  breakfast: singleton(pizza)

Where I planned to run:

@Override
public Object run(ScriptFragment scriptFragment) {
    String ref = scriptFragment.getArguments().get(0);

    Object singleton = singletons.get(ref);
    if (singleton == null) {
        objectMother.bear(ref, SOME_UNKNOWN_CLASS)
    }
}

But I don't have access to SOME_UNKNOWN_CLASS in this context, so I can't just cache it with a function

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