I am writing a piece of music where the song is in d melodic minor and there is a place where I play a D Major chord on bass F# (D/F#) and I sing for a brief moment an F note and guitar also play f note for brief moments at the same time. is that ok? I have trouble understanding if it's possible to sing with this dissonance even though it sounds nice to me:).
Strictly speaking, the quality of a I chord in melodic minor is XmMaj so I'd say that the F came to you naturally to highlight the minor 3rd or #9 generally associated with that chord. Now playing a DMAJ in a melodic minor progression is fine as long as you like what it sounds like. Melody is also about building tension and all the tones do not have to be chordal tones or scale tones. In Take the A train there is a Db played over a G7 chord (the b5 of the chord, the blue note) and although it's not so easy to sing it sounds nice and can be traced back to Jelly Roll Morton. So if it's good for Jelly Roll, it's good for you! Your musical taste should be your guide here.
In classical harmony, what you're doing is called a "simultaneous cross relation": playing chromatically related notes (F-natural & F-sharp in your case) at the same time. An easily accessible example from early in the common hormonic practice is in Tallis' Spem in alium, where the choirs arrive at A major & the altos of choir 1 (or is it choir 2?) leave the chord via a C-natural while the tenors in one of the other choirs are still holding the C-sharp. Spem dates from C16, & Tallis is one of the great names in the English choral tradition, so you're in great company.