You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Thomas Eckoldt (JIRA)" <ji...@apache.org> on 2008/06/09 14:45:45 UTC

[jira] Created: (WICKET-1690) Allow injection of models

Allow injection of models
-------------------------

                 Key: WICKET-1690
                 URL: https://issues.apache.org/jira/browse/WICKET-1690
             Project: Wicket
          Issue Type: Improvement
          Components: wicket-guice
            Reporter: Thomas Eckoldt


wicket-guice allows injection of components in a very transparent way - this should work the same way for models. In particular when working with loadable, detachable models it is desirable to inject a service implementation that is responsible for loading the model data. If such a model (see example code below) is not declared as nested class of a component but as a top-level class for reuse, model injection is needed.

Example:

{code}
public class ContactModel extends LoadableDetachableModel {

	private Long contactId;
	
	@Inject
	private ContactService service;
	
	public ContactModel(Long contactId) {
		this.contactId = contactId;
	}
	
	@Override
	protected Contact load() {
		return service.getContact(contactId);
	}

}
{code}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WICKET-1690) Allow injection of models

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-1690?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Igor Vaynberg resolved WICKET-1690.
-----------------------------------

    Resolution: Won't Fix
      Assignee: Igor Vaynberg

in the constructor of your model add this line:

InjectorHolder.getInjector().inject(this);

we cant transparently inject any class since that would require bytecode instrumentation. components have a special facility built in for that in their constructor, but imodel is an interface...


> Allow injection of models
> -------------------------
>
>                 Key: WICKET-1690
>                 URL: https://issues.apache.org/jira/browse/WICKET-1690
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-guice
>            Reporter: Thomas Eckoldt
>            Assignee: Igor Vaynberg
>
> wicket-guice allows injection of components in a very transparent way - this should work the same way for models. In particular when working with loadable, detachable models it is desirable to inject a service implementation that is responsible for loading the model data. If such a model (see example code below) is not declared as nested class of a component but as a top-level class for reuse, model injection is needed.
> Example:
> {code}
> public class ContactModel extends LoadableDetachableModel {
> 	private Long contactId;
> 	
> 	@Inject
> 	private ContactService service;
> 	
> 	public ContactModel(Long contactId) {
> 		this.contactId = contactId;
> 	}
> 	
> 	@Override
> 	protected Contact load() {
> 		return service.getContact(contactId);
> 	}
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1690) Allow injection of models

Posted by "Thomas Eckoldt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1690?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12603588#action_12603588 ] 

Thomas Eckoldt commented on WICKET-1690:
----------------------------------------

InjectorHolder.getInjector().inject(this) 

doesn't work for wicket-guice, or is there something more to consider?

> Allow injection of models
> -------------------------
>
>                 Key: WICKET-1690
>                 URL: https://issues.apache.org/jira/browse/WICKET-1690
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-guice
>            Reporter: Thomas Eckoldt
>            Assignee: Igor Vaynberg
>
> wicket-guice allows injection of components in a very transparent way - this should work the same way for models. In particular when working with loadable, detachable models it is desirable to inject a service implementation that is responsible for loading the model data. If such a model (see example code below) is not declared as nested class of a component but as a top-level class for reuse, model injection is needed.
> Example:
> {code}
> public class ContactModel extends LoadableDetachableModel {
> 	private Long contactId;
> 	
> 	@Inject
> 	private ContactService service;
> 	
> 	public ContactModel(Long contactId) {
> 		this.contactId = contactId;
> 	}
> 	
> 	@Override
> 	protected Contact load() {
> 		return service.getContact(contactId);
> 	}
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1690) Allow injection of models

Posted by "Thomas Eckoldt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1690?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12603592#action_12603592 ] 

Thomas Eckoldt commented on WICKET-1690:
----------------------------------------

There is actually a GuiceInjectorHolder but you need to get a reference as a static getInjector() method is missing...seems to be a bit more complicated, see http://www.nabble.com/Problem-with-Wicket-and-Guice-td14787021.html. I assume this is a downside of a non-managed framework - dependency injection is hard to integrate.


> Allow injection of models
> -------------------------
>
>                 Key: WICKET-1690
>                 URL: https://issues.apache.org/jira/browse/WICKET-1690
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-guice
>            Reporter: Thomas Eckoldt
>            Assignee: Igor Vaynberg
>
> wicket-guice allows injection of components in a very transparent way - this should work the same way for models. In particular when working with loadable, detachable models it is desirable to inject a service implementation that is responsible for loading the model data. If such a model (see example code below) is not declared as nested class of a component but as a top-level class for reuse, model injection is needed.
> Example:
> {code}
> public class ContactModel extends LoadableDetachableModel {
> 	private Long contactId;
> 	
> 	@Inject
> 	private ContactService service;
> 	
> 	public ContactModel(Long contactId) {
> 		this.contactId = contactId;
> 	}
> 	
> 	@Override
> 	protected Contact load() {
> 		return service.getContact(contactId);
> 	}
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-1690) Allow injection of models

Posted by "Igor Vaynberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-1690?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12603589#action_12603589 ] 

Igor Vaynberg commented on WICKET-1690:
---------------------------------------

i guess guice has its own GuiceInjectorHolder

> Allow injection of models
> -------------------------
>
>                 Key: WICKET-1690
>                 URL: https://issues.apache.org/jira/browse/WICKET-1690
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-guice
>            Reporter: Thomas Eckoldt
>            Assignee: Igor Vaynberg
>
> wicket-guice allows injection of components in a very transparent way - this should work the same way for models. In particular when working with loadable, detachable models it is desirable to inject a service implementation that is responsible for loading the model data. If such a model (see example code below) is not declared as nested class of a component but as a top-level class for reuse, model injection is needed.
> Example:
> {code}
> public class ContactModel extends LoadableDetachableModel {
> 	private Long contactId;
> 	
> 	@Inject
> 	private ContactService service;
> 	
> 	public ContactModel(Long contactId) {
> 		this.contactId = contactId;
> 	}
> 	
> 	@Override
> 	protected Contact load() {
> 		return service.getContact(contactId);
> 	}
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.