You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de> on 2015/09/03 19:44:56 UTC

MappedConfiguration for my service - how to access the map

Hi everyone,

I'm trying to add some configuration to my self-implemented service. How do I access the configuration properties? I can add to the configuration, override it, and inject it per IOC into the constructor of the service.

But how do I access the configuration?

Regards,
Daniel P.

AW: MappedConfiguration for my service - how to access the map

Posted by "Poggenpohl, Daniel" <Da...@isst.fraunhofer.de>.
Hello,

I managed to access the map. It seems I either misunderstood a documentation or something else happened because I thought I had to inject MappedConfiguration into my constructor.

But instead I have to inject Map which is of course accessible using the usual methods.

Regards,
Daniel P.

-----Ursprüngliche Nachricht-----
Von: Nathan Quirynen [mailto:nathan@pensionarchitects.be] 
Gesendet: Freitag, 4. September 2015 11:25
An: users@tapestry.apache.org
Betreff: Re: MappedConfiguration for my service - how to access the map

Hey,

I'm not sure what you mean. As you say it is injected into your service constructor, so you already have access to it no? You can inject your service wherever you want (pages, components, other services, ...) which holds the configuration you contributed in your module class.

A simple example:

|public| |class| |MyAppModule {
|
|public| |static| |void| 
|contributeMyService(|||MappedConfiguration<String, String>
configuration|) {|
|||configuration.add(||"first"||, "contribution");
||||    configuration.add(||"second"||, "contribution");|
|||    }
}
|

|public class| |MyService {

     private Map<String, String> config;
|||
|public| |MyService||(Map<String, String> configuration) {|
|||config = configuration;||
|
|}

     public String getConfigValue(String key) {
         return config.get(key);
     }
}
|

|public class| |MyPage||{
     @Inject
     private MyService myService;

     public getFirstConfigValue() {
         return myService.getConfigValue("first");
     }
}
|
Nathan

On 03/09/15 19:44, Poggenpohl, Daniel wrote:
> Hi everyone,
>
> I'm trying to add some configuration to my self-implemented service. How do I access the configuration properties? I can add to the configuration, override it, and inject it per IOC into the constructor of the service.
>
> But how do I access the configuration?
>
> Regards,
> Daniel P.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: MappedConfiguration for my service - how to access the map

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Not sure what happened to my code formatting.. hope this is better:

public class MyAppModule {

     public static void contributeMyService(MappedConfiguration<String, 
String> configuration) {
         configuration.add("first", "contribution");
         configuration.add("second", "contribution");
     }
}


public class MyService {

     private Map<String, String> config;

     public MyService(Map<String, String> configuration) {
         config = configuration;
     }

     public String getConfigValue(String key) {
         return config.get(key);
     }
}


public class MyPage {

     @Inject
     private MyService myService;

     public getFirstConfigValue() {
         return myService.getConfigValue("first");
     }
}


On 04/09/15 11:24, Nathan Quirynen wrote:
> Hey,
>
> I'm not sure what you mean. As you say it is injected into your 
> service constructor, so you already have access to it no? You can 
> inject your service wherever you want (pages, components, other 
> services, ...) which holds the configuration you contributed in your 
> module class.
>
> A simple example:
>
> |public| |class| |MyAppModule {
> |
> |public| |static| |void| 
> |contributeMyService(|||MappedConfiguration<String, String> 
> configuration|) {|
> |||configuration.add(||"first"||, "contribution");
> ||||    configuration.add(||"second"||, "contribution");|
> |||    }
> }
> |
>
> |public class| |MyService {
>
>     private Map<String, String> config;
> |||
> |public| |MyService||(Map<String, String> configuration) {|
> |||config = configuration;||
> |
> |}
>
>     public String getConfigValue(String key) {
>         return config.get(key);
>     }
> }
> |
>
> |public class| |MyPage||{
>     @Inject
>     private MyService myService;
>
>     public getFirstConfigValue() {
>         return myService.getConfigValue("first");
>     }
> }
> |
> Nathan
>
> On 03/09/15 19:44, Poggenpohl, Daniel wrote:
>> Hi everyone,
>>
>> I'm trying to add some configuration to my self-implemented service. 
>> How do I access the configuration properties? I can add to the 
>> configuration, override it, and inject it per IOC into the 
>> constructor of the service.
>>
>> But how do I access the configuration?
>>
>> Regards,
>> Daniel P.
>>

Re: MappedConfiguration for my service - how to access the map

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Hey,

I'm not sure what you mean. As you say it is injected into your service 
constructor, so you already have access to it no? You can inject your 
service wherever you want (pages, components, other services, ...) which 
holds the configuration you contributed in your module class.

A simple example:

|public| |class| |MyAppModule {
|
|public| |static| |void| 
|contributeMyService(|||MappedConfiguration<String, String> 
configuration|) {|
|||configuration.add(||"first"||, "contribution");
||||    configuration.add(||"second"||, "contribution");|
|||    }
}
|

|public class| |MyService {

     private Map<String, String> config;
|||
|public| |MyService||(Map<String, String> configuration) {|
|||config = configuration;||
|
|}

     public String getConfigValue(String key) {
         return config.get(key);
     }
}
|

|public class| |MyPage||{
     @Inject
     private MyService myService;

     public getFirstConfigValue() {
         return myService.getConfigValue("first");
     }
}
|
Nathan

On 03/09/15 19:44, Poggenpohl, Daniel wrote:
> Hi everyone,
>
> I'm trying to add some configuration to my self-implemented service. How do I access the configuration properties? I can add to the configuration, override it, and inject it per IOC into the constructor of the service.
>
> But how do I access the configuration?
>
> Regards,
> Daniel P.
>