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

Dropwizard UnitOfWork Guice Interceptor #42

Open
amr opened this issue Aug 17, 2017 · 4 comments
Open

Dropwizard UnitOfWork Guice Interceptor #42

amr opened this issue Aug 17, 2017 · 4 comments

Comments

@amr
Copy link

amr commented Aug 17, 2017

Hi,

This is my first submission to this project so allow me to begin by saying: Thank you for the awesome work.

Now, Dropwizard's @UnitOfWork only works on jersey resources by default. To get them to work for methods on classes that are not jersey resources, you have to manually instantiate such classes by running them through UnitOfWorkAwareProxyFactory. Example from Dropwizard docs:

SessionDao dao = new SessionDao(hibernateBundle.getSessionFactory());
ExampleAuthenticator exampleAuthenticator = new UnitOfWorkAwareProxyFactory(hibernateBundle)
               .create(ExampleAuthenticator.class, SessionDao.class, dao);

This of course goes against what we aspire to achieve by using a DI such as Guice.

Since guice has AOP I think this awesome bundle can ship optional support for @UnitOfWork outside resources, using Guice AOP.

Here is an example of such Guice module (briefly tested and it works): https://stackoverflow.com/a/38267726/43597

It can even just be included in the Hibernate example in the docs. I'd be happy to provide a PR if this deems plausible.

@xvik
Copy link
Owner

xvik commented Aug 17, 2017

Hi!
Yes, it would be great if you provide a PR for the hibernate example.
Please include extra test (to check that feature is working), if possible.

@oeddyo
Copy link

oeddyo commented May 8, 2020

this is actually quite amazing.
I tried it and it actually works :D

Do you think it's feasible to add it into Guicey or a standalone example should be enough? @xvik

@oeddyo
Copy link

oeddyo commented May 8, 2020

nvm I thought I get it working in my test case...

@xvik
Copy link
Owner

xvik commented May 8, 2020

Ideally, it should be improved and become a guicey-ext module to simplify configuration.
And I'm thinking about it time-to-time, but there is always something more important to do.

For now, there is only a basic hibernate example

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

3 participants