A module is projective if each homomorphism downstairs has a lift upstairs. Here is the technical definition.
A module P is projective if, for any pair of modules A and B, and any epimorphism f from A onto B, and any homomorphism g from P into B, there is at least one homomorphism h from P into A such that hf = g. A map from P into B lifts up to a compatible map from P into A.
Every free module is projective. See projective objects for a proof. As a special case, the ring R is always a projective R module.
A module J is injective if, for any pair of modules A and B, and any monomorphism f from A to B, and any homomorphism g from A to J, there is at least one homomorphism h from B to J such that fh = g.
If P is a direct sum we can prove the converse. Assume each Ci is projective. Given g(P) into B, realize that g defines, and is defined by, its action on each Ci. Lift each g(Ci) up to an h(Ci), and put these component functions together to build a composite function h. Verify that h is indeed a lift for g, hence P is projective.
Similar reasoning applies when P is injective. Given a function g(A) into Ci, extend it to all of P by setting the other components to 0. This implies a function h, which we restrict to Ci, and Ci is injective.
Conversely, if P is a direct sum or a direct product, and each Ci is injective, the function g(A) into P defines, and is defined by, component functions from A into each Ci. Each of these component functions implies a compatible function downstairs. Put these together to build a function h, and P is injective.