Dynamical evolution of massive perturbers in realistic multicomponent galaxy models I: implementation and validation