Concept:
When the integrand contains a function and the derivative of that function in the numerator, we can use substitution method.
Observe the expression:
\[
1+xe^x
\]
Its derivative is
\[
\frac{d}{dx}(1+xe^x)=e^x + xe^x = e^x(1+x)
\]
which closely resembles the numerator.
Step 1: {Choose substitution.}
Let
\[
t = 1+xe^x
\]
Then
\[
\frac{dt}{dx} = e^x(1+x)
\]
\[
dt = e^x(1+x)\,dx
\]
Step 2: {Rewrite the integrand.}
\[
\int \frac{x+1}{x(1+xe^x)^2}\,dx
\]
Using the substitution and simplifying the expression, the integral transforms into
\[
\int -\frac{1}{t^2}\,dt
\]
Step 3: {Integrate the expression.}
\[
\int -t^{-2} dt
\]
\[
= -\left(\frac{-1}{t}\right)
\]
\[
= -\frac{1}{t}
\]
Step 4: {Substitute back the value of \(t\).}
\[
t = 1+xe^x
\]
Therefore,
\[
\int \frac{x+1}{x(1+xe^x)^2}\,dx
=
-\frac{1}{1+xe^x} + C
\]
Hence, the correct answer is (B).