Mapping DSL Examples
1
mapPath("path")
2
mapDSL("cool", "model.CoolFactory");
3
4
map("SecurityService")
5
.to("model.security.SecurityService")
6
.onDICOmplete(["start","executeRoles"])
7
8
mapDirectory('/shared/model');
9
10
// Eager initialized objects
11
map("luis,joe").to("model.Luis").into(this.SCOPES.SINGLETON).asEagerInit()
12
map(["luis","joe"]).to("model.Luis").into(this.SCOPES.SINGLETON).asEagerInit()
13
14
// map a property to a mapping id via DSL
15
map("Lui").toDSL("coldbox:setting:luis")
16
17
// using initWith() for passing name-value pairs or positional arguments for direct initialization of a mapping
18
map("transferConfig")
19
.to("transfer.com.config.Configuration")
20
.initWith(datasourcePath=getProperty('datasourcePath'),
21
configPath=getProperty('configPath'),
22
definitionPath=getProperty('definitionPath'));
23
24
// Now doing with setter injection
25
map("transferConfig")
26
.to("transfer.com.config.Configuration")
27
.setter(name="datasourcePath", value=getProperty("datasourcePath"))
28
.setter(name="configPath", value=getProperty("datasourcePath"))
29
.setter(name="definitionPath", value=getProperty("definitionPath") );
30
31
32
// Map with constructor arguments
33
map("transfer")
34
.to("transfer.com.Transfer")
35
.into(SCOPES.SINGLETON)
36
.noAutowire()
37
.asEagerInit()
38
.initArg(name="configuration",ref='transferConfig'); //ref = name by default, or have an explicit name
39
40
// RSS Integration With Caching.
41
map("googleNews")
42
.toRSS("http://news.google.com/news?pz=1&ned=us&hl=en&topic=h&num=3&output=rss")
43
.asEagerInit()
44
.inCacheBox(timeout=20,lastAccessTimeout=30,provider="default",key="google-news");
45
46
// Java Integration with init arguments
47
map("Buffer").
48
toJava("java.lang.StringBuffer").
49
initArg(value="500",javaCast="long");
50
51
// Java integration with initWith() custom arguments and your own casting.
52
map("Buffer").
53
toJava("java.lang.StringBuffer").
54
initWith( javaCast("long",500) );
Copied!
Last modified 1yr ago
Copy link