Return-Path: Delivered-To: apmail-cayenne-dev-archive@www.apache.org Received: (qmail 31382 invoked from network); 16 Nov 2009 14:29:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Nov 2009 14:29:45 -0000 Received: (qmail 83719 invoked by uid 500); 16 Nov 2009 14:29:44 -0000 Delivered-To: apmail-cayenne-dev-archive@cayenne.apache.org Received: (qmail 83687 invoked by uid 500); 16 Nov 2009 14:29:44 -0000 Mailing-List: contact dev-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list dev@cayenne.apache.org Received: (qmail 83677 invoked by uid 99); 16 Nov 2009 14:29:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Nov 2009 14:29:44 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [72.14.220.153] (HELO fg-out-1718.google.com) (72.14.220.153) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Nov 2009 14:29:36 +0000 Received: by fg-out-1718.google.com with SMTP id d23so2633392fga.10 for ; Mon, 16 Nov 2009 06:29:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.86.195 with SMTP id w45mr1114802wee.82.1258381755483; Mon, 16 Nov 2009 06:29:15 -0800 (PST) In-Reply-To: <036B6634-9744-4E31-98B3-5856DCA8AC20@objectstyle.org> References: <3219fff70906010809lb53131age67e865246947f90@mail.gmail.com> <806E1194-A47C-4A5A-AE03-B70C35BCEF64@roxanemy.com> <525d8e10906030442i62101329j583ab8e68e12a5c6@mail.gmail.com> <0CFADF10-B797-4CA1-BF06-33E3B5F6489F@objectstyle.org> <7BA57AD2-4ABE-4E6F-8F96-E7FAC9044925@objectstyle.org> <7e3605160910271401h1107559fq784ba410dece4140@mail.gmail.com> <036B6634-9744-4E31-98B3-5856DCA8AC20@objectstyle.org> From: Michael Gentry Date: Mon, 16 Nov 2009 09:28:55 -0500 Message-ID: <5adb61290911160628q667ce73eh6de7cb0f28ef2f75@mail.gmail.com> Subject: Re: IOC container To: dev@cayenne.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org How are you envisioning injecting an ObjectContext for different DataNodes,= etc? Thanks, mrg On Sun, Nov 15, 2009 at 4:57 PM, Andrus Adamchik w= rote: > Just for kicks wrote a simple DI container for Cayenne. I checked it in > partially to sanbdox folder until the ASF SVN repo went down > (http://monitoring.apache.org/), so I'll commit the rest on Monday, or > whenever SVN becomes available. > > This no-frills DI container took me only a couple of hours to write (it > borrows some Guice API, but implementation is all mine). It supports > > * annotation-based field dependency injection > * binding interfaces to implementation classes via fluent API > * binding interfaces to "provider" (same as "factory") classes > * merging multiple DI "modules". > > The whole thing is only 14K after compilation (so it beats all full featu= red > DI containers in size). Of course that's because it doesn't have all the > fancy stuff (of which we'll add at least a few more things) such as > constructor injection, dependency cycle resolving, dynamic interface > proxies, bound object lifecycle, integration with Spring, etc. Since we a= re > not planning a general purpose container, we might survive without most o= f > those. > > Here is how the current Configuration class might look like when it is ba= sed > on DI: > > public class Configuration { > > =A0 =A0 =A0 =A0private Injector injector; > > =A0 =A0 =A0 =A0public Configuration() { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this(new CayenneModule()); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0public Configuration(Module... modules) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0this.injector =3D DIBootstrap.createInject= or(modules); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0public DataChannel getDataChannel() { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return injector.getInstance(DataChannel.cl= ass); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0public ObjectContext getNewContext() { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return injector.getInstance(ObjectContext.= class); > =A0 =A0 =A0 =A0} > > =A0 =A0 =A0 =A0// we may create getters for other "services" if we need t= o > } > > And the actual configuration class (aka "module") used above: > > public class CayenneModule implements Module { > > =A0 =A0 =A0 =A0public void configure(Binder binder) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0binder.bind(EventManager.class).to(EventMa= nagerImpl.class); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0binder.bind(DataChannel.class).to(DataDoma= in.class); > > =A0binder.bind(QueryCache.class).toProvider(LRUCacheFactory.class); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0binder.bind(QueryLogger.class).toProvider(= FancyLogger.class); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0// an so on... > =A0 =A0 =A0 =A0} > } > > "CayenneModule" is what users can override (e.g. simply subclass), provid= ing > alternative implementations for some services. > > The next step in this prototype would be an attempt to define the current > Cayenne stack in terms of DI. > > Andrus > > On Oct 27, 2009, at 11:01 PM, Kevin Menard wrote: > >> On Sun, Oct 25, 2009 at 5:05 PM, Andrus Adamchik >> wrote: >> >>> And I just discovered that both Spring (3.0RC1) and Juice (trunk) suppo= rt >>> the annotations from this JSR. So it could make sense for us to use the= se >>> annotations internally as well. Couldn't dig any info on the Tapestry I= oC >>> support for this JSR, but they are on the JSR "support group", so at >>> least >>> they are watching it. >> >> Thiago, the Tapestry member on the support group, just learned that it >> had been approved. =A0Howard didn't even know the JSR existed. =A0There'= s >> no discussion on adding in the annotation support to Tapestry IoC and >> I suspect it will happen, but Tapestry is behind the ball on that one. >> >> -- >> Kevin >> > >