question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support adding class instances in the PicoContainer with the PicoFactory

See original GitHub issue

Summary

Improvement request: support adding class instances when extending the PicoFactory to setup the global context.

Expected Behavior

As the PicoContainer supports adding component that are class instances, it could be interesting to also offer this functionality using the PicoFactory.

Current Behavior

It is only possible to add a component in the PicoContainer based on a given Class with the public boolean addClass(Class<?> clazz) method.

Possible Solution

I wrote a custom PicoFactory based on yours and the changes were quite simple:

I replaced the following line:

private final Set<Class<?>> classes = new HashSet<Class<?>>();

By:

private final Set<Object> classes = new HashSet<Object>();

And I added this method:

public void addClass(Object classInstance) {
    classes.add(classInstance);
}

Context & Motivation

I wanted to inject mocks of some interfaces in my support classes to run my acceptance tests in a smaller scope but I couldn’t find an elegant way to do so using the PicoFactory.

I can submit a PR with these changes if you want.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
aslakhellesoycommented, Oct 31, 2018

Give us some more time stalebot - I’m still interested in this.

0reactions
stale[bot]commented, Oct 4, 2020

This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dependency Injection - Cucumber Pico Container
Create a base/foundation class that initializes your driver object/ page objects classes. Use @Before annotation for defining setup and @After ...
Read more >
Factory Injection - PicoContainer
This allows an instance to be injected via a factory that is aware of the thing it ... This type of injection is...
Read more >
Using Dependency Injectors to Simplify Your Code in Cucumber
Class objects in and get object instances back. Most of all that is needed to know to use DIs effectively in Cucumber is...
Read more >
State - Cucumber Documentation
Cucumber will create a new instance of each of your glue code classes before each ... To use PicoContainer, add the following dependency...
Read more >
Usage of PicoContainer - Documentation - Confluence
CliAnalyzer cliAnalyzer = pico.getComponent(CliAnalyzer. class );. Here you create a new container, add CliAnalyzer as a dependency and get the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found