Added strict validation for event registration in middleware