-
Notifications
You must be signed in to change notification settings - Fork 95
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
Injectable Modules, Named configuration data, and Injected Commands #46
base: master
Are you sure you want to change the base?
Conversation
Altered GuiceBundle to allow setting of ServletContextListeners
…ting injector annotation just to be make it clear it's primarly used for configuring based on setting annotations?
Fantastic work @oillio and @yunspace. I found a bug in jersey2-guice that caused
to not be injected into the jersey resources (Squarespace/jersey2-guice#22) properly. Hopefully they'll accept my PR (Squarespace/jersey2-guice#23) and then let's upgrade the dependency. I thought you should know as I first suspected that it was the order we initialize things in that was the culprit, but it wasn't! |
} | ||
|
||
@Run | ||
public void run(@Named("defaultName") String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also inject HelloWorldConfiguration as a method parameter? Really neat feature:)
@jontejj Thanks. Let me know when jersey2-guice accepts your patch and I will rev the dependency version. |
Will do. I think he tried to merge my PR but got formatting issues. Soon...
|
@yunspace and @jontejj I am thinking about forking the project, registering it with Maven Central, and using this branch as the mainline. The three of us seem to be the most active users. So, a survey: Do you agree that moving to a fork is waranted? Do you like the improvements made in this branch, and do you agree this should be the mainline? |
We have definitely not abandoned this project! We have 200+ services in production using dropwizard-guice and have no plans to use something else. Unfortunately we are still on dropwizard 0.6, but I can try to get this and #45 merged into master and cut a new release |
@oillio @jontejj @HiJon89 whilst I think staying on the mainline is good to leverage the existing community base, I do feel that it may be slightly overwhelming for HubSpot to support new features and issues related to dropwizard 0.8 when the bulk of their services are on 0.6. Also #45 is practically a different code base using a third party library. The core There is no doubt the good folks at HubSpot have built a pretty stable foundation in Just my 2 cents. But if we do need a fork, I actually have Continuous Delivery pipeline and unofficial BinTray repository set up for #45 (just need to change namespace etc): |
Thanks @HiJon89. Sorry to jump the gun. After 3 moths without a commit or comment I was just getting a bit nervous. I don't care who owns the project so long as we get timely releases and code reviews; I don't want to have to continue to maintain a private build and branch. If you need help maintaining the 0.8 branch, I am happy to help. |
I'm happy to help support 0.8 release also if this project will remain active and timely. Once the 0.8 changes are merged, I will re-point my CI and BinTray setup back to here. |
We are still here. My office is a few blocks from HubSpot and I am using 0.7 but I could move easily to 0.8 since I only have two services in my new company so far. I am away this weekend so let's get this sorted out Monday. I have been meaning to catch up on .8 and jersey 2. — On Fri, Feb 20, 2015 at 6:01 PM, Dan Jasek [email protected]
|
@oillio I don't like the idea of binding configuration properties using |
Great suggestion Jonathan. Once my jersey2-guice fix is in we can even
|
That sounds good to me and should be easy to implement. I think it will also help me fix another annoyance with the current design. Mind if I call it @config instead? |
OK, I converted it to use a new annotation called @config.
You can get to data with either of these attributes:
This is particularly useful if FooConfig, and the classes using "data" are in an external library. This way, the library doesn't have to know where exactly FooConfig is located within the parent project's config object, just so long as it is there somewhere. |
Fixed. |
I'm going to see if I can make dropwizard-guice extensible enough to support these use-cases easily (maybe with a new type of |
Sounds good. The @config stuff can be pretty cleanly moved to an independent Guice module. Do you want me to split that feature out into a separate pull request? |
Sure |
Also, I meant a separate Maven module for the common extensions |
Yep. I was going to pull the @config stuff out of DropwizardEnvironmentModule into it's own Guice module. So, when you go to implement the extension hooks, it will be easier to refactor it out into the extension Maven module. |
I pulled out the @config functionality from this PR and moved it to its own PR. |
Great, I'll take a look tomorrow |
When pulling the @config code out I noticed that, with the double injection feature, we may not need the user to set the configurationClass. Is there any scenario where the configurationClass should not be configuration.getClass()? If the answer is no, I should be able to remove setConfigClass and significantly simplify DropwizardEnvironmentModule. |
Break out configuration code. Implement InjectedCommands. Added tests. Various bug fixes and refactorings.
Conflicts: .gitignore README.md pom.xml src/main/java/com/hubspot/dropwizard/guice/AutoConfig.java src/main/java/com/hubspot/dropwizard/guice/GuiceBundle.java src/test/java/com/hubspot/dropwizard/guice/AutoConfigTest.java src/test/java/com/hubspot/dropwizard/guice/GuiceBundleTest.java src/test/java/com/hubspot/dropwizard/guice/objects/ExplicitResource.java src/test/java/com/hubspot/dropwizard/guice/objects/InjectedTask.java
I'm going to try and see if I can merge the 2 test applications: |
Sounds good. Thanks. As it stands, it is a bit difficult to follow the tests and understand why certain bits are setup the way they are. I wanted to test end to end functionality, going through the Jersey integration, and I couldn't come up with a better way to do it. If you have any better ideas... |
As I began splitting the tests into 2 groups:
I believe this was what @HiJon89 was hinting at by splitting the extensions? Whilst the double injection functionality is quite powerful and forms the basis for What does everyone think? In the mean while I've made a rough start on option 1, but haven't progressed very far. Will submit a PR to @oillio's branch when it's in a good state. |
I worry that splitting them up adds additional complexity for the user with little gain. Under what scenario would a user not want to use double injection? For more advanced users, they can add injected fields to their modules and add initialization modules as needed without any configuration change or change to performance or functionality. If we split up the functionality into two modules, the transition would take additional effort and understanding. I would agree that the @config functionality could be an optional addon. There is additional configuration required to make it work as expected and a potential performance hit for complex configuration objects. |
…Merged tests into single test suite with a single config.yml and shared packages. Also: * Removed test-config.yml and TestModule, to use hello-world.yml and HelloWorldModule * Removed ConfigData (covered by JITDao) and HelloWorldConfig.otherData (unused) * Removed InjectedEnvironmentCommandTest.test_simple_case() which is repeated. * Added extra test in IntegrationTest to cater specifically eager singletons as per HubSpot#19
Complexity for the users is a fair point. But I think it's also reasonable that many users just use single injection for simple injections and don't have any issues related to In the spirit of keeping the library lean and easy to understand, I've move things around a bit. All the double injection related stuff are in a separate sub-package, along with their tests. It's a lot clearer now (I hope) who is using who, and may form a good basis for future refactoring. I wrote new test catering for #19. where users want to create a eager singleton In regards to @oillio previous question:
I don't understand why the user needs to set Configuration class either. Can anyone shed some light? Or in the spirit of TDD, the best way probably write a test case for both scenarios and see if the results end up the same. |
Refactored double injection related code and tests into sub package
…op the module. This can happen when running a Command that does not have an environment when modules are defined that depend on the environment.
We have made a number of additions to dropwizard-guice.
I'm thinking the upgrade to Dropwizard 0.8 might be a good chance to see if any of these additions would be of interest to the project (the attached code is currently based off my 0.8 update PR).
The additions are (usage descriptions can be found in the updated readme):