This would fall under sex outside of wedlock and bringing life into the world without providing the fathering that was meant to be.
Correct: Genesis 38:9-10.
However, the rationale is comparable.
God created Adam & Eve (men & women) with natural laws to pass down to their descendants.
Medical manipulation and lasciviousness have destroyed those golden rules.
Incest by proxy, adolescent promiscuity, revolving shack-ups or multiple ‘marriages’, lack of male parenting and homosexuality are all contributing to the destruction of a Godly society.
One note on the Onan story, that "wife" you speak of was his brother's widow and under Law he owed her a child that would be called his brother's. He was struck down for repeated disobedience because any child with her would not be known as his.