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.