const mixinafIoc::ServiceOverride

afIoc::ServiceOverride

(Service) - Contribute to override previously defined services. Use to override production services with test versions, or to replace 3rd party services with your own implementation.

Use the service Id to specify the original service to override, and pass in the override instance. For example, to override the PieAndChips service with an instance of PieAndMash:

static Void bind(ServiceBinder binder) {
  binder.bind(PieAndChips#)
}

@Contribute { serviceType=ServiceOverride# }
static Void contributeServiceOverride(MappedConfig conf) {
  conf["myPod::PieAndChips"] = conf.autobuild(PieAndMash#)
}

Or taking advantage of Type Coercion, you can use the Type as the key:

@Contribute { serviceType=ServiceOverride# }
static Void contributeServiceOverride(MappedConfig conf) {
  conf[PieAndChips#] = conf.autobuild(PieAndMash#)
}

Obviously, the overriding class has to fit the original service type.

Note at present you can not override perThread scoped services and non-const (not immutable) services.

@since 1.2

@uses MappedConfig of Str:Obj (serviceId:overrideImpl)