A methodology to describe nanoindentation by means of discrete dislocations is presented. A collocation method is used to calculate the arising contact stresses at each indentation step, which permits to realize an arbitrary shape of the indenter. Distributed dislocation sources are allowed to emit dislocations on predefined slip planes, when the critical value of the local shear stress for the emission is reached. After each indentation step, the newly emitted dislocations are brought to their equilibrium positions under the influence of the stresses induced by the contact stresses and the dislocations. As an application of our model, the plastic behavior of two materials with different densities of dislocation sources will be studied in detail.