because the framework so far is limiting you in using the default
constructor, remember that the steps for the instantiation of an HK2
components are as follow :
- new()
- injection
- postConstruct()
since you need to have an instance created to be able to do the
injection in, the framework need to use the zero args one since it
would not know how to get the constructor parameters values.
Remember that you don't directly instantiate the @Service yourself,
you usually inject it or do a habitat.getComponent(Foo.class) type of
call so there is no way you would be able to specify the values at
this point.
For instance you could have a different implementation of your Foo
contract that takes very different set of constructor parameters,
there is no way the framework can have a generic way of dealing with
@Contract implementation details.
What you seem to want to do is something like :
@Factory(FooFactory.class)
@Contract
interface Foo {
...
}
@Service
class FooFactory implements Factory {
Object getObject() {
return new ServiceThatExtends(input);
}
}
Jerome
On Apr 7, 2008, at 9:11 AM, glassfish_at_javadesktop.org wrote:
> Hi,
>
> I have a problem implementing one service:
> Example code:
>
> abstract class AbstractClass{
>
> public AbstractClass(String input){
> ...
> }
>
> }
>
> @Contract
> interface Foo{
>
> public void doIt();
> }
>
>
>
> @Service
> public class ServiceThatExtends extends AbstractClass implements Foo{
>
> ServiceThatExtends(String input){
> super(input);
> }
>
> public void doIt(){
> }
>
> }
>
>
> In this case we don not use the default contructor and I get a
> Unsatisfied dependency exception, but why do we always have to use
> the default constructor in Services?
> [Message sent by forum member 'antsh' (antsh)]
>
> http://forums.java.net/jive/thread.jspa?messageID=268016
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>