Skip to content

Dropwizard UnitOfWork Guice Interceptor #42

@amr

Description

@amr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions