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

Dagger Support #166

Open
joolurik opened this issue Jan 8, 2023 · 1 comment
Open

Dagger Support #166

joolurik opened this issue Jan 8, 2023 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@joolurik
Copy link

joolurik commented Jan 8, 2023

Hello,

I am looking to enable similar mocking for Dagger based dependency injection systems. I know dagger doesn't support AOP but want to quickly check here for extending this framework for Dagger.

FYI, Dagger is a compile time dependency injection framework and is getting popular in the recent times. https://medium.com/bigeye/dependency-injection-103-guice-vs-dagger-6ab7afa68d3d

Thanks,

@JanSchankin JanSchankin self-assigned this Jan 8, 2023
@JanSchankin
Copy link
Contributor

JanSchankin commented Jan 8, 2023

Hi joolurik,

sounds quite interesting! DeepSampler has an abstraction layer for AOP, so it should be independent of concrete AOP frameworks. We designed DeepSampler this way to be able to do exactly what you are suggesting!

Concept

We have an abstract concept, that we like to call aop-provider. In fact, this is the starting point of DeepSampler, you could see it as the main()-method of DeepSampler.
An aop-provider lives inside of a particular aop-framework. It's job is to intercept method-calls and to send these method-calls to DeepSampler. The way, how this is done, is completely open to the authors of aop-providers.

An example can be found in GuiceSamplerAspect.java and another one in SpringSamplerAspect.java, I suggest to start with the guice-version because it is much simpler than Spring.

Dagger integration ideas

So, the interesting part of that project would be to find a way to integrate something that is able to intercept method-calls in Dagger. One solution that I can think of might be AspectJ with compile-time-weaving. In fact, this might even be a generalized solution that could work nearly everywhere, independent of any dependecy-injection-framework. We were thinking of writing this, but haven´t found the time yet.

A quick google search showed this: custom-annotation-interceptor-using-dagger-2 on StackOverflow. This might also be something to look into.

Modularization

You could create a module (using maven or gradle) deepsampler-provider-dagger that lives in your own GitHub repo. It would have the same dependencies to DeepSampler as deepsampler-provider-guice. You could publish this module to maven-central, so that others can use it together with DeepSampler.

Testing

Since a test-framework is meant to ensure the quality of the test-objects, it's quite important to thoroughly test the test-framework itself. We have two abstract Junit-test-classes that can be used to test all aop-providers and to ensure that all providers support the same functionality. But it would be great if you could add some additional tests, that we maybe didn't think of.

@JanSchankin JanSchankin added the question Further information is requested label Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants