First Effort in "Right Effort" The first effort states to prevent the arising of unarisen unwholesome states

How is this done? How can we prevent something beforehand? By avoiding situations? By trying to be in a rational and/or 'dhammic' frame of mind? 

If there is contact with an object, either ignorance or wisdom arises subsequently in response, and AFTER THAT, we can use sati-sampajañña to get rid of the unwholesome state (2nd factor of right effort).

But how is the first factor to be practised?
The following theme for reflection from AN 5.57 (quoted below) can prevent the arising of unarisen unwholesome states. It encourages shame of evil (hiri) and fear of evil (otappa), which are mentioned as beautiful mental factors in the Abhidhamma.


  “And for the sake of what benefit should a woman or a man, a
  householder or one gone forth, often reflect thus: ‘I am the owner of
  my kamma, the heir of my kamma; I have kamma as my origin, kamma as my
  relative, kamma as my resort; I will be the heir of whatever kamma,
  good or bad, that I do’? People engage in misconduct by body, speech,
  and mind. But when one often reflects upon this theme, such misconduct
  is either completely abandoned or diminished. It is for the sake of
  this benefit that a woman or a man, a householder or one gone forth,
  should often reflect thus: ‘I am the owner of my kamma, the heir of my
  kamma; I have kamma as my origin, kamma as my relative, kamma as my
  resort; I will be the heir of whatever kamma, good or bad, that I do.’