You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Michael Mattox <mi...@verideon.com> on 2005/06/22 17:31:49 UTC

Example of HiveMind constructor injection

Greetings,

I got the Datum setter injector working but I cannot get it to work with
constructor injection.  My service looks like this:

public class MyServiceImpl implements MyService {

  List data;

  public MyServiceImpl(List data) {
    super();
    System.out.println("Constructor called.");
  }

and my hivemodule.xml:

<module id="hivemindtest.di" version="1.0.0" package="hivemindtest.di">

	<configuration-point id="Simple">
	  <schema>
		<element name="datum">
		  <attribute name="key" required="true"/>
		  <attribute name="value" required="true"/>

		  <conversion class="hivemindtest.di.DatumImpl"/>
		</element>
	  </schema>
	</configuration-point>

	<contribution configuration-id="Simple">
	  <datum key="key1" value="value1"/>
	  <datum key="key2" value="value2"/>
	</contribution>

	<service-point id="MyService" interface="hivemindtest.di.MyService">
	  <invoke-factory>
		<construct class="hivemindtest.di.MyServiceImpl">
		  <set-configuration property="data" configuration-id="Simple"/>
		</construct>
	  </invoke-factory>
	</service-point>

</module>


When I run I get this:

org.apache.hivemind.ApplicationRuntimeException: Unable to construct
service hivemindtest.di.MyService: Error building service
hivemindtest.di.MyService: Unable to find constructor applicable for
autowiring. Use explicit constructor parameters.

But I have no idea how to "use explicit constructor parameters".  I've
read through the documentation and I cannot find anything.  I've searched
for the <construct & <set-configuration tags in the module descriptor
documentation but nothing is found.  I'm really stuck.

I've used Pico before so I'm familar with the concepts, I just can't seem
to make sense out of the HiveMind documentation.  In searching the mailing
list, I am of the impression that the 1.1-beta1 version does not include
everything needed for constructor injection OR the documentation is not up
to date.  I found a JIRA issue for example on injecting a single object
instead of a list or map, but I don't know if the patch was accepted (I
don't think so, the issue hasn't been updated).  It seems this would be
required for constructor injection, if not all the constructor parameters
would be of type List, which would make a pretty hard to use constructor.
:)

I hope all this makes sense.  I'm looking forward to using HiveMind on
this project and I thank you all for your help.

-Michael



--
This E-mail is confidential.  It may also be legally privileged.  If you are
not the addressee you may not copy, forward, disclose or use any part of it.
If you have received this message in error, please delete it and all copies
from your system and notify the sender immediately by return E-mail.
Internet communications cannot be guaranteed to be timely, secure, error or
virus-free.  The sender does not accept liability for any errors or omissions.


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


RE: Example of HiveMind constructor injection

Posted by Michael Mattox <mi...@verideon.com>.
> http://jakarta.apache.org/hivemind/hivemind/BuilderFactory.html#Constructor+
> Parameter+Elements
>
> So, in your example, I would imagine that it's...
>
> <construct class="hivemindtest.di.MyServiceImpl">
>   <configuration>Simple</configuration>
> </construct>

Thanks for the help, I got my simple example working.  Now I think I have
one more case, slightly more complicated and then I can feel at ease with
using HiveMind for the dependency injection.

I have an object Encryptor which encrypts URLs.  It has a dependency which
is a String encryptionKey.  Now I have two services which use this
Encryptor, and each of them will need to configure the Encryptor with a
different encryption key.

I think it's pretty straightforward to do this if I only use one
encryption key.  But I don't understand how I can configure two instances
of the Encryptor.  This situation comes up a lot in fact, because some of
my services have to be configured with a client id and there are several,
some have a language, etc.  So rather than pass these dependencies as
parameters to each method, I'd like to have an instance of my service for
each case.  For example, an instance for english, an instance for french. 
I hope this makes sense.

If you can tell me how to structure the hivemodule.xml file for this
scenario I'd be very grateful.  Thanks again for everyone's help!

-Michael



--
This E-mail is confidential.  It may also be legally privileged.  If you are
not the addressee you may not copy, forward, disclose or use any part of it.
If you have received this message in error, please delete it and all copies
from your system and notify the sender immediately by return E-mail.
Internet communications cannot be guaranteed to be timely, secure, error or
virus-free.  The sender does not accept liability for any errors or omissions.


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


RE: Example of HiveMind constructor injection

Posted by James Carman <ja...@carmanconsulting.com>.
http://jakarta.apache.org/hivemind/hivemind/BuilderFactory.html#Constructor+
Parameter+Elements

So, in your example, I would imagine that it's...

<construct class="hivemindtest.di.MyServiceImpl">
  <configuration>Simple</configuration>
</construct>

-----Original Message-----
From: Michael Mattox [mailto:michael@verideon.com] 
Sent: Wednesday, June 22, 2005 11:32 AM
To: hivemind-user@jakarta.apache.org
Subject: Example of HiveMind constructor injection

Greetings,

I got the Datum setter injector working but I cannot get it to work with
constructor injection.  My service looks like this:

public class MyServiceImpl implements MyService {

  List data;

  public MyServiceImpl(List data) {
    super();
    System.out.println("Constructor called.");
  }

and my hivemodule.xml:

<module id="hivemindtest.di" version="1.0.0" package="hivemindtest.di">

	<configuration-point id="Simple">
	  <schema>
		<element name="datum">
		  <attribute name="key" required="true"/>
		  <attribute name="value" required="true"/>

		  <conversion class="hivemindtest.di.DatumImpl"/>
		</element>
	  </schema>
	</configuration-point>

	<contribution configuration-id="Simple">
	  <datum key="key1" value="value1"/>
	  <datum key="key2" value="value2"/>
	</contribution>

	<service-point id="MyService" interface="hivemindtest.di.MyService">
	  <invoke-factory>
		<construct class="hivemindtest.di.MyServiceImpl">
		  <set-configuration property="data"
configuration-id="Simple"/>
		</construct>
	  </invoke-factory>
	</service-point>

</module>


When I run I get this:

org.apache.hivemind.ApplicationRuntimeException: Unable to construct
service hivemindtest.di.MyService: Error building service
hivemindtest.di.MyService: Unable to find constructor applicable for
autowiring. Use explicit constructor parameters.

But I have no idea how to "use explicit constructor parameters".  I've
read through the documentation and I cannot find anything.  I've searched
for the <construct & <set-configuration tags in the module descriptor
documentation but nothing is found.  I'm really stuck.

I've used Pico before so I'm familar with the concepts, I just can't seem
to make sense out of the HiveMind documentation.  In searching the mailing
list, I am of the impression that the 1.1-beta1 version does not include
everything needed for constructor injection OR the documentation is not up
to date.  I found a JIRA issue for example on injecting a single object
instead of a list or map, but I don't know if the patch was accepted (I
don't think so, the issue hasn't been updated).  It seems this would be
required for constructor injection, if not all the constructor parameters
would be of type List, which would make a pretty hard to use constructor.
:)

I hope all this makes sense.  I'm looking forward to using HiveMind on
this project and I thank you all for your help.

-Michael



--
This E-mail is confidential.  It may also be legally privileged.  If you are
not the addressee you may not copy, forward, disclose or use any part of it.
If you have received this message in error, please delete it and all copies
from your system and notify the sender immediately by return E-mail.
Internet communications cannot be guaranteed to be timely, secure, error or
virus-free.  The sender does not accept liability for any errors or
omissions.


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org