Do you crate him when you leave? If so, perhaps he is objecting to the confinement. Try this. Put something he really likes to eat in his crate about 20 minutes or so before you are going out. Lock him out of the crate. By the time you are ready to leave, he will likely want that crate door open! (you can condition this before you use it for going out by doing it when you have no plans to leave.) If a crate isn't the issue and you normally leave him loose, just leave!
The longer you allow this behavior, the harder it will be to stop it. If you are going out, shut him out of the bedroom. Put a leash on him if necessary before he knows what's up. In fact, it is of course great to do that a couple of times a day for a few minutes so he doesn't KNOW what is coming. Treat when leashing. Treat and happy praise when you take it off. Get the leash, put in the crate and treat. Leave for a minute, let out of crate. Keep repeating til you can easily get him into the crate. Make the crate more fun.. food, toys, etc, because this is a 2 fold problem –- he is acting bad (which you cannot allow to continue) because he hates his crate. Working on getting him in there a LOT for a few minutes of something good on a regular basis should help decrease the drama til you can stop with the leash in a couple of months. OBVIOUSLY remove the leash in the crate and collar too if you are using one.
Pearl used to be aggressive when she was asleep and we tried to move her. She would snarl, rather scary. We just stopped trying to move her. Really we wanted to roll her over to pet her tummy. So we just went over and let her know we were there, and pet her without moving her. She grew out of it, I guess, cause now she kind of rolls over by herself. I lover her so much!
A way to do what Debra is suggesting in a game format is Crate Games, which you can get on DVD.
You said this happens when you are getting ready to leave. Pay attention to exactly what you are doing before you leave and then see how your dog is reacting. You should be able to pick up on the cues that your dog is picking up on. You can try changing the pattern of how you get ready and potentially remove the cue to lessen the behavior until you can build the good associations others described.
visit BCOA on Facebook. http://facebook.com/basenji.org