AuthFilter
does not need to be declared as a service - you could new up an instance in the contribute() method:
@Contribute { serviceType=HttpPipeline# }
static Void contributeHttpPipeline(OrderedConfig conf) {
authFilter := AuthFilterImpl()
conf.addOrdered("AuthFilter", authFilter, ["after: BedSheetFilters"])
}
If AuthFilter
has dependencies on other services (for example, it has fields annotated with @Inject
) then afIoc should build the instance for you. The OrderedConfig
and MappedConfig
objects have a handy autobuild()
method just for this:
authFilter := conf.autobuild(AuthFilterImpl#)
If you want AuthFilter
to be injected into other services, or you want to contribute to it, then it needs to be defined as an afIoc service. Use the bind()
method in your AppModule
to do this:
static Void bind(ServiceBinder binder) {
binder.bind(AuthFilter#, AuthFilterImpl#)
}
It may then be parameter injected into the contribute method, just as you had in your example:
@Contribute { serviceType=HttpPipeline# }
static Void contributeHttpPipeline(OrderedConfig conf, AuthFilter authFilter) {
conf.addOrdered("AuthFilter", authFilter, ["after: BedSheetFilters"])
}
See afIoc - definingServices for more details. The BedSheetModule may also be a good reference for afIoc examples.