JeffFaer / junit5-extensions

Personal repository for JUnit 5 extensions
MIT License
40 stars 8 forks source link

Cached injector for common modules #3

Closed Litemn closed 6 years ago

Litemn commented 6 years ago

In original implementantion for each test guice create new injector and if we bind somting in scope SINGLETON - that not work as expected.

In this pr I provide basic implementation of cache for injectors with same modules - can you provide some feedback? @JeffreyFalgout

JeffFaer commented 6 years ago

What's your use case? Why would you want to share singleton instances across tests?

Litemn commented 6 years ago

At least connection pools to DB or some shared state (I know that shared states is bad idea, but sometimes it very helpful)

JeffFaer commented 6 years ago

Ideally you would fake out the DB connection so it isn't terribly expensive, but I can see some value in a feature like this.

I don't think it should be enabled by default, but adding some annotation that lets users opt into shared injectors would be reasonable

Litemn commented 6 years ago

I add @SharedInjectors annotation for cached inhectors enabled

JeffFaer commented 6 years ago

Looks good, thanks for bearing with me!

JeffFaer commented 6 years ago

This will be available as part of 1.1.0