He was born in Bologna, then part of the Papal States, and began studying music early, learning harpsichord and violin there; later he studied counterpoint. By the age of 17 he had already written a mass, a motet, and a setting of the Magnificat; and in 1678 he wrote his first opera and oratorio. During a stay in Parma, where he studied with Giuseppe Corsi da Celano, he formed his sacred music style; most of his psalm settings of the 1680s and 1690s show the influence of Corsi. Later he went to Venice, most likely for a production of one of his operas.