That is the example we have with Joseph who was sold into slavery by his brothers and then imprisoned for a crime he didn't commit. After he became second-in-command in Egypt and help save thousands of lives by preparing for the drought God told him would come. In this same way he was able to save his brothers. Joseph told these men; "But don't be angry with yourselves that you did this to me, for God did it. He sent me hear ahead of you to preserve your lives" (Genesis 45:5; NLT). God used the evil actions of Joseph's brothers to get Joseph right where Joseph needed to be.
Joseph was able to see how God continued to work through the evil in his life to bring about God's plan. Yet Joseph only experienced this wonderful blessing because he continued to obey God through it all. Joseph would have missed the "reason" for his suffering if he did not remain faithful to God.
When we are faced with evil circumstances in our lives we have the option to give up and participate in the sin which we find all around us or we can resolve to go with God no matter what happens. The problem with the second choice is that it could take years before we see the light at the end of the tunnel, and along the way there will be many more opportunities to give up.
This is why it is so important to have people in our lives who will encourage us and help us along the right path (one reason I find Joseph so amazing is that he remained faithful to God even though he lacked the support system of other God Followers). The writer of Hebrews reminds us:
Without wavering, let us hold tightly to the hope we say we have, for God
can be trusted to keep his promises. Think of ways to encourage one another
to outbursts of love and good deeds. And let us not neglect our meeting
together, as some people do, but encourage and warn each other, especially now that the day of his coming back again is drawing near (Hebrews 10:23-35; NLT).
In this evil world bad things happen, dreams shatter, and hearts are broken. It is a reality of life and so we need to remember that God will redeem these thing if we are faithful to Him. He will use the worst and most painful experiences in our lives for good. God will not let the pain of His children go to waste.