You can create a rule for the service interface, that specifies, which classes may implement the interface.
@Service(permits = { MongoUserService.class, MySQLUserService.class })
interface UserService {
}
@Service
class MongoUserService implements UserService {
}
@Service
class MySQLUserService implements UserService {
}
@Service
class PostgresUserService implements UserService {
}
void initUserService() {
Container.implement(UserService.class, MongoUserService.class);
Container.implement(UserService.class, MySQLUSerService.class);
// both should work fine
Container.implement(UserService.class, PostgresUserService.class);
// will throw an `InvalidServiceAccessException`
}