The concept of Niyoga might sound barbaric to us but it was practiced even by the other cultures likes Jews though in a different form.
Niyoga is an ancient Hindu tradition in which a woman is allowed to have sex with her deceased husband’s brother or a revered person in the society with the sole purpose of having a child. The woman must be either a widow or her husband is incapable of having a child.
There were some rules associated with Niyoga such as the man would do this only to help the woman to have a child and not to have pleasure. He was allowed to do this for a maximum of three times only in his life. The consent of woman was necessary. The child born with the help of this process was considered as a child of the woman and her husband. The appointed man would not seek any relationship to the child.
Examples of Niyoga are found in Mahabharata. There are some Indian movies who used Niyoga as the central theme for the movie.
This is a very ancient tradition and is not in practice now.