Comments (9)
@coreywoodfield I don't think that this is a good idea to store jam specific metadata in the class itself... I'm suggesting to consider following solutions:
val a: A = jam.brew(new A(_: String))
or
def fromString(c: String): A = new A(c)
val a: A = jam.brew(fromString _)
Feel free to reopen the issue if you will have some related ideas.
from jam.
I think we've found a use case for this feature. The Play Framework automatically generates routing code, and for its compile-time dependency injection, you can construct the router using components that you manually pass to the generated constructor.
We're trying to migrate some things over to Jam, but the issue that we're running into is that the Play Framework generates two constructors, and annotates one with that standard javax.inject.Inject annotation, basically like this:
class Routes(
override val errorHandler: play.api.http.HttpErrorHandler,
Application_0: controllers.Application,
bar_Routes_0: bar.Routes,
Assets_1: controllers.Assets,
val prefix: String
) extends GeneratedRouter {
@javax.inject.Inject()
def this(
errorHandler: play.api.http.HttpErrorHandler,
Application_0: controllers.Application,
bar_Routes_0: bar.Routes,
Assets_1: controllers.Assets
) = this(Application_0, bar_Routes_0, Assets_1, "/")
...
}
Unfortunately, this means we get the More than one primary constructor was found for (router.Routes)
error when we try to construct the routes with Jam. We also can't control the generation of the routing code, and I think the alternative is to have to pass in every individual controller, which can be difficult within larger projects like ours. This issue is sort of blocking our migration from Macwire to Jam, so we were hoping to have Jam be able to handle annotations, even if it's just for annotating a "primary" constructor with javax.inject.Inject
like Macwire does; does that seem compatible with your long-term views for the project, @yakivy?
from jam.
@denvercoder10 extra java dependency doesn't fit in my long-term view, but I also cannot leave you without a solution... What about extra jsr330
module with brew
method that will read javax.inject.Inject
annotation? It will look like:
jam.jsr330.brew[Routes]
from jam.
That solution seems great to me, @yakivy!
from jam.
@coreywoodfield yes, sure, but I'm talking not only about ivy dependencies, code behaviour depends on javax.inject
annotation and needs to be maintained as a part of core lib. But maybe I'm being too stubborn, I need some time to rethink this idea...
from jam.
We saw that, and we really appreciate your effort! Thanks so much, this has been really helpful for a hackathon this week :)
from jam.
I've got a proof of concept PR up to support the javax.inject.Inject
annotation. If anyone has feedback on it or how it would fit into the project, feel free to let me know!
from jam.
I will point out that the opened PR only added the new dependency to tests. No dependencies were added to the core jam code
from jam.
So I let perfectionism go 😄
I merged PR but with minor refactoring (I don't trust toString
methods). 0.0.12
is already published.
from jam.
Related Issues (9)
- Can't find constructor of classes nested in objects (scala 2) HOT 2
- Can't handle type parameters (scala 2) HOT 1
- Doesn't inject non-implicit parameters that are implicit fields (scala 2) HOT 2
- Can't inject Strings (scala 2) HOT 1
- Error messages when using type tagging are confusing HOT 3
- [Feature Request] It'd be nice if there were an equivalent to macwires `wireWith` method HOT 1
- [Feature request] Allow values of type B to be injected for constructor args of type A if B <: A HOT 1
- Brewing from case classes creates ambiguity HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jam.