The operator $P=-i\hbar\frac{d}{dx}$, is a symmetric operator in the domain $$D(P)=\left\{f(x) \big|f\in L_2[0, a], f(0)=f(a)=0\right\}$$ i.e. the domain is the subspace of square-integrable functions in the interval $0\leq x\leq a$ that vanish at the endpoints $x=0$ and $x=a$. The adjoint turns out to be $P^\dagger=i\hbar\frac{d}{dx}$.
The operator $P$ is symmetric but not self-adjoint because $D(P^\dagger)\neq D(P)$ where $$D(P^\dagger)=\left\{g(x) \big|g\in L_2[0,a]\right\}$$
If we want to apply this idea to the problem of a quantum particle in a box (infinite square well), then the wavefunctions representing all possible states of the system are both square-integrable and vanish at endpoints. So $-i\hbar\frac{d}{dx}$ is automatically self-adjoint. We don't need a self-adjoint extension. Am I right?