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/28 10:06:17 UTC

Finally got it! Example of HiveMind constructor injection

I finally got some simple examples working, using constructor injection. 
I have a service which accepts a configuration object, and I create two
instances with two different configurations.  Then I create another
service which takes a configuration and also the two instances of the
previous services.  This represents the dependencies of my project.  I
think it'd be great if the HiveMind documentation on the website included
an example like this.  It's pretty simple once you figure it out but I
must say I had a hard time figuring it out and getting it to work.  I
don't want to criticize the HiveMind documentation, but I do want to say
that I'm pretty impressed with HiveMind and I'm afraid that if the
documentation isn't better then people might give up on it and not use it,
which would be a shame.  If I can help with him just let me know.  I'm
including the config and constructors here so that anyone searching the
mailing list for an example (like I was) will find one..

Here's the config (let me know if I'm doing anything stupid):

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

	<configuration-point id="config-point-CSA">
	  <schema>
		<element name="csa">
		  <attribute name="key" required="true"/>
		  <conversion class="hivemindtest.di2.ConfigurationServiceAImpl"/>
		</element>
	  </schema>
	</configuration-point>
	<contribution configuration-id="config-point-CSA">
	  <csa key="key1"/>
	</contribution>

	<configuration-point id="config-point-CSA2">
	  <schema>
		<element name="csa">
		  <attribute name="key" required="true"/>
		  <conversion class="hivemindtest.di2.ConfigurationServiceAImpl"/>
		</element>
	  </schema>
	</configuration-point>
	<contribution configuration-id="config-point-CSA2">
	  <csa key="key2"/>
	</contribution>

	<service-point id="ServiceA1" interface="hivemindtest.di2.ServiceA">
	  <invoke-factory>
		<construct class="hivemindtest.di2.ServiceAImpl">
		  <configuration>config-point-CSA</configuration>
		</construct>
	  </invoke-factory>
	</service-point>

	<service-point id="ServiceA2" interface="hivemindtest.di2.ServiceA">
	  <invoke-factory>
		<construct class="hivemindtest.di2.ServiceAImpl">
		  <configuration>config-point-CSA2</configuration>
		</construct>
	  </invoke-factory>
	</service-point>

	<service-point id="ServiceB" interface="hivemindtest.di2.ServiceB">
	  <invoke-factory>
		<construct class="hivemindtest.di2.ServiceBImpl">
		  <configuration>config-point-CSA2</configuration>
		  <service>ServiceA1</service>
		  <service>ServiceA2</service>
		</construct>
	  </invoke-factory>
	</service-point>

</module>

And the constructors:

  public ServiceAImpl(List<ConfigurationServiceA> config) {}

  public ServiceBImpl(List<ConfigurationServiceA> config, ServiceA serviceA,
      ServiceA serviceA2) {}

Hope that helps someone, it would have saved me a lot of time.  Thanks to
the people on this list for helping me not only with their replies but
with all the info in the mailing list archives.

Michael Mattox



--
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