{"action":"created","issue":{"url":"https://api.github.com/repos/eclipse/microprofile-config/issues/332","repository_url":"https://api.github.com/repos/eclipse/microprofile-config","labels_url":"https://api.github.com/repos/eclipse/microprofile-config/issues/332/labels{/name}","comments_url":"https://api.github.com/repos/eclipse/microprofile-config/issues/332/comments","events_url":"https://api.github.com/repos/eclipse/microprofile-config/issues/332/events","html_url":"https://github.com/eclipse/microprofile-config/issues/332","id":308023030,"number":332,"title":"Standardize support for MP Config in EL","user":{"login":"arjantijms","id":3037006,"avatar_url":"https://avatars2.githubusercontent.com/u/3037006?v=4","gravatar_id":"","url":"https://api.github.com/users/arjantijms","html_url":"https://github.com/arjantijms","followers_url":"https://api.github.com/users/arjantijms/followers","following_url":"https://api.github.com/users/arjantijms/following{/other_user}","gists_url":"https://api.github.com/users/arjantijms/gists{/gist_id}","starred_url":"https://api.github.com/users/arjantijms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arjantijms/subscriptions","organizations_url":"https://api.github.com/users/arjantijms/orgs","repos_url":"https://api.github.com/users/arjantijms/repos","events_url":"https://api.github.com/users/arjantijms/events{/privacy}","received_events_url":"https://api.github.com/users/arjantijms/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-23T13:09:34Z","updated_at":"2018-03-23T14:20:56Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"It's often handy to be able to use MP config in EL expressions, but currently this is not supported out of the box.\r\n\r\nEL support can be added in a variety of ways, for instance by defining an implicit object (provided CDI bean with a default name), via a custom EL resolver, or by statically importing `ConfigProvider` (getELContext().getImportHandler().importClass(...)).\r\n\r\nMaybe the implicit object is the easiest way and also allows for better namespacing. \r\n\r\nAn example of using MP Config in EL would be in the yet to be defined annotation to install JWT authentication:\r\n\r\n```java\r\n@JWTConfig(\r\n    issuer = \"#{microprofile.config['my.accepted.issuer']}\"\r\n)\r\n```\r\n\r\nHere the main implicit object is `microprofile`, which serves as a namespace as well as an access point to potentially other microprofile services. \r\n\r\n`config` would be a Map here that essentially wraps `ConfigProvider.getConfig()` and only supports a few operations. There's a few additional options that could be explored, for instance use method expressions, where the backing code can automatically pass in the class type for the `getValue(String propertyName, Class<T> propertyType)` call, based on the type of the EL expression (if known).\r\n\r\nAs another example, existing MP Annotations could be extended with EL enabled attributes, so they can use a more elaborate pull style config in addition to the existing config methods that override globally or per service, to e.g. config per group of services:\r\n\r\n```java\r\n@CircuitBreaker(\r\n    successThreshold = 10, \r\n    requestVolumeThreshold = 4, \r\n    failureRatio=0.75, \r\n    delayExpression = \"#{microprofile.config['com.example.groupx.delay']}\")\r\npublic Connection serviceA() {}\r\n```\r\n\r\nYet another example is on Facelets templates:\r\n\r\n```xml\r\n<h:panelGroup rendered=\"#{microprofile.config['app.featureX.enabled']}\">\r\n    <!-- Some markup here -->\r\n</h:panelGroup>\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/eclipse/microprofile-config/issues/comments/375680463","html_url":"https://github.com/eclipse/microprofile-config/issues/332#issuecomment-375680463","issue_url":"https://api.github.com/repos/eclipse/microprofile-config/issues/332","id":375680463,"user":{"login":"OndrejM","id":2195988,"avatar_url":"https://avatars0.githubusercontent.com/u/2195988?v=4","gravatar_id":"","url":"https://api.github.com/users/OndrejM","html_url":"https://github.com/OndrejM","followers_url":"https://api.github.com/users/OndrejM/followers","following_url":"https://api.github.com/users/OndrejM/following{/other_user}","gists_url":"https://api.github.com/users/OndrejM/gists{/gist_id}","starred_url":"https://api.github.com/users/OndrejM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OndrejM/subscriptions","organizations_url":"https://api.github.com/users/OndrejM/orgs","repos_url":"https://api.github.com/users/OndrejM/repos","events_url":"https://api.github.com/users/OndrejM/events{/privacy}","received_events_url":"https://api.github.com/users/OndrejM/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T14:20:56Z","updated_at":"2018-03-23T14:20:56Z","author_association":"CONTRIBUTOR","body":"I agree that having a standard named object to access configuration from an EL is useful. Especially to access configuration in templates (JSF, facelets, etc.)\r\n\r\nBut I don't think that having support for ELs in annotation values is the best solution to have scriptable configuration for interceptors. 2 reasons:\r\n- each field in the annotation would have to be doubled to accept EL instead of a value (this wouldn't have to be done for fields of type String but definitely for other types like int)\r\n- it's better to use Java code in Java code rather than uncompiled and untyped EL\r\n\r\nI suggest to evaluate a different approach to provide some logic to the configuration, e.g. by supplying another class that would provide methods to configure them, e.g.:\r\n\r\n```\r\n@CircuitBreaker(\r\n    successThreshold = 10, \r\n    configProvider = MyCustomConfigProvider.class\r\n)\r\n\r\n@Dependent\r\nclass MyCustomConfigProvider  {\r\n    @Inject Config config;\r\n    \r\n    void configure(CircuitBreakerBuilder builder) {\r\n        builder.setDelay(config.getValue(\"com.example.groupx.delay\", Integer.class));\r\n    }\r\n}\r\n"}}
{"actor":{"display_login":"OndrejM"}}