You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Konrad Windszus <kw...@apache.org> on 2023/06/27 07:05:00 UTC
Sling Models Constructor Injection
Hi,
Currently our documentation at [1] only outlines using the annotations on method level for constructor injection:
@Inject public MyModel(@Named("propertyName") String propertyName) { // constructor code }
However as we recommend using injector-specific annotation now, I am wondering if annotations can also be used on argument level only?
public MyModel(@Named("propertyName”) @ValueMapValue String propertyName, @OSGiService MyService myService) { // constructor code }
If someone can confirm that both levels are supported for constructor injection I am gonna adjust our documentation.
Thanks,
Konrad
[1] - https://sling.apache.org/documentation/bundles/models.html#model-classes
Re: Sling Models Constructor Injection
Posted by Konrad Windszus <kw...@apache.org>.
Some things magically work even without ITs.
And no, by someone I really meant some committer.
> On 27. Jun 2023, at 11:36, Bertrand Delacretaz <bd...@apache.org> wrote:
>
> On Tue, Jun 27, 2023 at 9:05 AM Konrad Windszus <kw...@apache.org> wrote:
>> ...If someone can confirm that both levels are supported for constructor injection
>> I am gonna adjust our documentation...
>
> Well, "someone" should be "automated tests", right? Otherwise it
> didn't happen ;-)
>
> -Bertrand
Re: Sling Models Constructor Injection
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Jun 27, 2023 at 9:05 AM Konrad Windszus <kw...@apache.org> wrote:
> ...If someone can confirm that both levels are supported for constructor injection
> I am gonna adjust our documentation...
Well, "someone" should be "automated tests", right? Otherwise it
didn't happen ;-)
-Bertrand