MappedConfiguration for my service - how to access the map

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

MappedConfiguration for my service - how to access the map

Poggenpohl, Daniel
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.
Reply | Threaded
Open this post in threaded view
|

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

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

Reply | Threaded
Open this post in threaded view
|

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

nquirynen
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.
>>
Reply | Threaded
Open this post in threaded view
|

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

Poggenpohl, Daniel
In reply to this post by nquirynen
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:[hidden email]]
Gesendet: Freitag, 4. September 2015 11:25
An: [hidden email]
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: [hidden email]
For additional commands, e-mail: [hidden email]