We consider the Dirac equation with a magnetic-solenoid field (the
superposition of the Aharonov--Bohm solenoid field and a collinear uniform
magnetic field). Using von Neumann's theory of the self-adjoint extensions of
symmetric operators, we construct a one-parameter family and a two-parameter
family of self-adjoint Dirac Hamiltonians in the respective 2+1 and 3+1
dimensions. Each Hamiltonian is specified by certain asymptotic boundary
conditions at the solenoid. We find the spectrum and eigenfunctions for all
values of the extension parameters. We also consider the case of a regularized
magnetic-solenoid field (with a finite-radius solenoid field component) and
study the dependence of the eigenfunctions on the behavior of the magnetic
field inside the solenoid. The zero-radius limit yields a concrete self-adjoint
Hamiltonian for the case of the magnetic-solenoid field. In addition, we
consider the spinless particle in the regularized magnetic-solenoid field. By
the example of the radial Dirac Hamiltonian with the magnetic-solenoid field,
we present an alternative, more simple and efficient, method for constructing
self-adjoint extensions applicable to a wide class of singular differential
operators.