The Gradle docs state (49.9):
Properties and methods declared in a project are inherited to all its
subprojects. This is an alternative to configuration injection. But we
think that the model of inheritance does not reflect the problem space
of multi-project builds very well. In a future edition of this user
guide we might write more about this.
I understand what configuration injection is doing in principle, but I'd like to understand more about the distinctions from inheritance, and why it's a better fit for multi-project builds.
Can anyone give me a few bullets on this?
Got the answer on the Gradle forums.
Essentially, configuration injection allows you to selectively apply properties to subprojects.
Related
I've been using c3p0 with hibernate for a couple of years. When looking at exception stack traces, I see classes such as com.mchange.v2.c3p0.impl.NewProxyPreparedStatement in the stack. I went looking for the source code for these classes and came across the curous com.mchange.v2.c3p0.codegen package.
In particular, it looks like JdbcProxyGenerator is metaprogramming in Java. I'm having a hard time understanding the codegen mechanism and why it is used. The built jar contains these generated classes, so I'm assuming these classes are built during the build, perhaps as part of a two-phase build. The codegen package does not appear to be in the generated jar.
Any insight would be appreciated, just for my own curiosity. Thanks!
yes, you are absolutely right.
c3p0 uses code generation to generate non reflective proxy implementations of large JDBC interfaces, "java bean" classes with lots of properties, and some classes containing debug and logging flags (to set up conditional compilation within the build).
You can always see the generated classes by typing ant codegen in the source distribution, and then looking at the build/codebase directory. The latest binary distribution of c3p0 (0.9.2-pre2) includes the generated sources in a src.jar file, which you can also find as a maven artifact at http://repo1.maven.org/maven2/com/mchange/c3p0/0.9.2-pre2-RELEASE/c3p0-0.9.2-pre2-RELEASE-sources.jar
I hope this helps!
I want to use dependency injection (Unity) and at the moment I'm thinking about how to setup my project (it's a fancy demo I'm working on).
So, to fully decouple all components and have no more assembly dependencies, is it advisable to create an assembly ".Contracts" or something similar and put all interfaces and shared data structures there?
Would you consider this the best practice or am I on a wrong track here?
What I want to accomplish:
Full testability, I want all components as sharply decouples as possible and inject everything, no component will ever talk directly to a concrete implementation anymore.
The first and probably most important step is to program to interfaces, rather than concrete implementations.
Doing so, the application will be loosely coupled whether or not DI is used.
I wouldn't separate interfaces in other assembly. If you have to interact with something that is a part of your domain, why separate it? Examples of interfaces are repositories, an email sender, etc. Supose you have a Model assembly where you have your domain objects. This assembly exposes the interfaces, and implementations, obviously, reference Model in order to implement them.
Does anyone know how to have dependency injection work with linq2sql. Heres my situation..
I will explain it as best i can here.
I have a base class which has a DBML (linq2sql) and classes etc .. This DBML is COMMON to more than 1 project.. Well each project has its own DBML but has all the tables etc that is in the common dbml i am using in the base class - does that make sense?!
Each of my projects creates a new class by inheriting the base class and extending it... but of course i need to REINJECT my dbml because the dbml that i use specifically in my project has all the functionality that was in COMMON and then some
I am a little lost here.. Anyone know how to achieve this.. I do hope i explained it well enough :-)
I was hoping to use unity or something similar, the classes that are created by linq2sql don't seem to implement interfaces... is this going to be a issues with DI?
Thanks
It sounds like you probably don't need a DBML in every project. I would recommend having one project "MyCoolApp.Entities" that contains your Linq to SQL entities, and then reference that project in your other projects. Those other projects can extend your base entities as needed.
As for Dependency Injection, Unity can definitely resolve dependencies that don't implement interfaces so that shouldn't be a problem.
I'd like to know what is the most efficient way of handling properties in Scala. I'm tired of having gazillion property files, xml files and other type of configuration files in Java and wonder if there's "best practice" to handle those someway more efficient in Scala?
Why would you have a gazillion property files?
I'm still using the Apache commons Digester, which works perfectly well in Scala. It's basically a very easy way of making a user-defined XML document map to method calls on a user-defined configurator class. I find it extremely useful when I want to parse some configuration data (as opposed to application properties).
For application properties, you might either use a dependency injection framework (like Spring) or just plain old property files. I'd also be interested to see if Scala offers anything on top of this, though.
EDIT: Typesafe config gives you a simple and powerful solution for configuration - https://github.com/typesafehub/config
ORIGINAL (possibly not very useful):
Quoting from "Programming in Scala":
"In Scala, you can configure via Scala code itself."
Scala's runtime linking allows for classes to be swapped at runtime and the general philosophy of these languages tends to favour convention over configuration. If you don't want to deal with gazillion property files, just don't have them.
Check out Configgy which looks like a neat little library. It includes nesting and change-notification. It also include a logging library.
Unfortunately, it didn't compile for me on the Mac instances I tried. Let us know if you have better luck and what you think...
Update: solved Mac compilation problems. See this post.
I am curious about the usage of the feature known as open classes or monkey-patching in languages like e.g. Ruby, Python, Groovy etc. This feature allows you to make modifications (like adding or replacing methods) to existing classes or objects at runtime.
Does anyone know if major frameworks (such as Rails/Grails/Zope) make (extensive) use of this opportunity in order to provide services to the developer? If so, please provide examples.
Rails does this to a (IMHO) ridiculous extent.
.Net allows it via extension methods.
Linq, specifically, relies heavily on extension methods monkey-patched onto the IEnumerable interface.
An example of its use on the Java platform (since you mentioned Groovy) is load-time weaving with something like AspectJ and JVM instrumentation. In this particular case, however, you have the option of using compile-time weaving instead. Interestingly, one of my recent SO questions was related to problems with using this load-time weaving, with some recommending compile-time as the only reliable option.
An example of AspectJ using load-time (run-time) weaving to provide a helpful service to the developer can be Spring's #Configuration annotation which allows you to use Dependency Injection on object not instantiated by Spring's BeanFactory.
You specifically mentioned modifying the method (or how it works), and an example of that being used is an aspect which intercepts am http request before being sent to the handler (either some Controller method or doPost, etc) and checking to see if the user is authorized to access that resource. Your aspect could then decide to return – prematurely – a response with a redirect to login. While not modifying the contents of the method per se, you are still modifying the way the method works my changing the return value it would otherwise give.