In the legato style piece, this is not easy to do - you have to apply smooth fingering and see that the middle part remains fluent and melodically as well as rhythmically intact.
Such a piece is for today's sight-reading: the famous Schmucke dich, o liebe Seele, Op. 122, No. 5 (1896) by Johannes Brahms (1833-1897), a 19th century late Romantic master German composer. Interestingly, such a sweet piece (p. 18), along with other 10 beautiful chorale preludes have been composed just one year before composer's death.
The unit value (the most frequently seen rhythmical value) in this piece is a sixteenth note. Therefore, shorten the repeated notes in the upper voice with the chorale tune by the sixteenth note making them dotted eighth notes and sixteenth note rests.
If three highly independent lines are too complex for you to play them together right away, play separate voices only in a slow tempo (especially this middle part). Watch out that all the parts would be played in a smooth legato. For this to happen, apply finger substitution.