CustomConditionChecker

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
}
}

See also

@Condition

Properties

Link copied to clipboard
abstract val annotationType: Class<A>

The condition annotation processed by this condition checker.

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.