使用afBedSheet 文档中的示例:
using afIoc
using afBedSheet
class HelloPage {
Text hello(Str name, Int iq := 666) {
return Text.fromPlain("Hello! I'm $name and I have an IQ of $iq!")
}
}
class AppModule {
@Contribute { serviceType=Routes# }
static Void contributeRoutes(Configuration conf) {
conf.add(Route(`/index`, Text.fromPlain("Welcome to BedSheet!")))
conf.add(Route(`/hello/**`, HelloPage#hello))
}
}
class Example {
Int main() {
return afBedSheet::Main().main([AppModule#.qname, "8080"])
}
}
如果我将此行添加为示例类中 main() 方法的第一行
registry := IocService([AppModule#]).start.registry
afBedSheet 应用程序不会启动并抛出:
[21:40:10 11-Aug-14] [info] [afIoc] Adding module definition for Example_0::AppModule
[21:40:10 11-Aug-14] [info] [afIoc] Starting IOC...
[21:40:10 11-Aug-14] [err] [afIoc] Err starting IOC
afIoc::IocErr: Service does not exist for Type 'afBedSheet::Routes' defined in contribution method Example_0::AppModule.contributeRoutes.
Ioc Operation Trace:
[ 1] Building IoC Registry
[ 2] Validating contribution definitions
Stack Trace:
afIoc::Utils.stackTraceFilter (Utils.fan:45)
afIoc::RegistryBuilder.build (RegistryBuilder.fan:108)
afIoc::IocService.onStart (IocService.fan:76)
fan.sys.Service$.start (Service$.java:206)
afIoc::IocService.start (IocService.fan:10)
Example_0::Example.main (/Users/coder/Documents/temp/testBedSheet/Example.fan:20)
java.lang.reflect.Method.invoke (Method.java:483)
fan.sys.Method.invoke (Method.java:559)
fan.sys.Method$MethodFunc.callOn (Method.java:230)
fan.sys.Method.callOn (Method.java:139)
fanx.tools.Fan.callMain (Fan.java:175)
fanx.tools.Fan.executeFile (Fan.java:98)
fanx.tools.Fan.execute (Fan.java:37)
fanx.tools.Fan.run (Fan.java:298)
fanx.tools.Fan.main (Fan.java:336)
ERROR: fan.afIoc.IocService.onStart
如何访问 afBedSheet 应用程序的 IocService 以获取绑定服务?