Custom Condition Checker
Defines custom conditions used while checking service instantiability.
Whether the service creation failure throws or not, is defined by Condition.fail, or if a dependent service requires it.
Requirement: A no-arg constructor must exist, or must be a Kotlin object
.
Example:
// Referenced by @RequireProfile
object ProfileChecker : CustomConditionChecker<RequireProfile> {
// Let's just say it's loaded from the config
private val currentProfile = Profile.DEV
override val annotationType = RequireProfile::class.java
override fun checkServiceAvailability(
context: BContext,
checkedClass: Class<*>,
annotation: RequireProfile
): String? {
if (annotation.profile != currentProfile) {
return "Profile ${annotation.profile} is required, current profile is $currentProfile"
}
return null
}
}
Content copied to clipboard
See also
@Condition
Functions
Link copied to clipboard
abstract fun checkServiceAvailability(serviceContainer: ServiceContainer, checkedClass: Class<*>, annotation: A): String?
Checks if the given class can be instantiated, if an error message is returned, the service cannot be instantiated.