In the modern ocean, many corals have dinoflagellates which live inside the tissues of the coral. The dinoflagellates continue to photosynthesize, as long as they have light and nutrients. However, they do not keep the products of photosynthesis for themselves. They release almost all of it into the tissues of the coral.
Coral reefs are very abundant in clear warm tropical waters of the world.
The corals metabolize the photosynthetic products, and of course produce wastes. They do not release those into sea-water until the dinoflagellates have extracted the nutrients from them, especially phosphate and nitrate. The nutrients are thus re-cycled between dinoflagellates and coral, so that the photosynthesis can keep going. The photosynthesis results in the release of oxygen, which the corals use in respiration. The carbon dioxide that the corals produce in respiration is absorbed by the dinoflagellates in their photosynthesis.