blob: f81f3e1a852baed0deee8ef863fad08949508bf1 [file] [log] [blame]
///////////////////////////////////////////////////////////////
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
///////////////////////////////////////////////////////////////
[[tut-services-step3,Step 3 - Reading the Service Configuration]]
= Step 3 - Reading the Service Configuration =
Services typically have configuration. Configurations are directly supported in Zest™. A
ConfigurationComposite is a subtype of EntityComposite. That is because
configurations are stored in EntityStores, can be modified in runtime by client code and has
the same semantics as regular entities.
Zest™ also handles the bootstrapping of configuration for the services. If the ConfigurationComposite is
not found in the configured entity store, then Zest™ will automatically locate a properties file for each
service instance, read those properties into a ConfigurationComposite instance, save that to the
entity store and provide the values to the service. The properties file must be with the same name as
the service instance with the extension "properties" in the same package as the service.
For this exercise, create a LibraryConfiguration that contains "titles", "authors" and "copies".
The first two are a string with a comma separated list, and the "copies" is just an Integer with how many
copies are made of each title.
Steps to do.
- Create a LibraryConfiguration interface that extends ConfigurationComposite, and has three Property instances named "titles", "authors" and "copies", where the first two are of String type and the last is of Integer type.
- Delete the LibraryActivator and remove the @Activators annotation from the LibraryService and the corresponding createInitialData method.
- In the LibraryMixin remove the member injection of the ValueBuilderFactory, and instead inject the ValueBuilderFactory in the constructor.
- Inject the LibraryConfiguration via the constructor. The injection scope is @This.
- Create a resource called LibraryService.properties and place it in the directory org/qi4j/tutorials/services/step4 in the classpath (for instance, src/main/resources ). Put something like this in:
titles=Domain Driven Design, Pragmatic Programmer, Extreme Programming Explained
authors=Eric Evans, Andy Hunt, Kent Beck
#Number of copies of each book.
copies=3
- Load initial data from the LibraryConfiguration in the LibraryMixin constructor.