I just came out of a 2.5 year stint. Before that I went into consulting because I couldn't hold down a job for even a year. I figured it was boredom and thought the solution was to simply expose myself to a constant stream of new problems. Turns out it was simply
ownership that was the problem. I never felt in control.
By ownership I mean ownership of my domain (area of involvement, etc) in the project. I don't mean ownership as in control and possession. The kind of ownership that kept me around at my last gig was the kind that let me make suggestions, criticisms, and decisions that were taken seriously. I had responsibility to back up every claim I made and that responsibility kept me highly motivated to produce software I could. It made the project feel more collaborative and kept me involved as a part of its development.
What kills that motivation is a loss of that ownership. In the final months of my last gig we brought on someone who took total ownership of the project practically from design to implementation. It no longer felt collaborative. I felt like a monkey in a room of monkeys trying to type out Shakespeare; as if I could replace myself with a junior programmer at half my salary and things would still run smoothly. That's not a good feeling and such loss of ownership (or lack of it in the first place) is completely demoralizing.
I get the sense that the OP was referring to this kind of ownership. The kind that makes you feel involved and responsible.
But does that mean you should quit your job? I don't think so. Some jobs will have ups and downs. I didn't leave my job when they brought the new guy on. I was going to stick it out... just circumstance brought my tenure there shorter than anticipated. I think you can stick it out in this way as well and avoid "depression." I take pride in my work and it does affect me very personally.. but you have to keep things in perspective. Especially when you have other people relying on you to keep your job.