8. Given a quadratic equation with real coefficients
$$
x^{2}+(1+a) x+a+b+1=0
$$

with two real roots $x_{1}, x_{2}$, and $0<x_{1}<1<x_{2}$. Then the range of $\frac{b}{a}$ is $(\quad)$.
(A) $\left(-1,-\frac{1}{2}\right]$
(B) $\left(-1,-\frac{1}{2}\right)$
(C) $\left(-2,-\frac{1}{2}\right]$
(D) $\left(-2,-\frac{1}{2}\right)$
8.D.

Let $f(x)=x^{2}+(1+a) x+a+b+1$. From $01$, we get
$$
\left\{\begin{array}{l}
f(0)=a+b+1>0 . \\
f(1)=2 a+b+3<0 .
\end{array}\right.
$$

In the right-angle coordinate plane $a O b$,
the region represented by the above inequalities
is shown as the shaded part in Figure 7 (excluding the boundaries). The intersection point of the two lines
$$
a+b+1=0 \text { and } 2 a+b+3
$$
$=0$ is $P(-2,1)$.
$\frac{b}{a}$ represents the slope of the line $l$ passing through the origin
$O$ and a point $(a, b)$ within the feasible region. Clearly, when $l$ passes through the point $P(-2,1)$, the slope is $-\frac{1}{2}$; when $l$ is parallel to the line $2 a+b$ $+3=0$, the slope is -2. Therefore, $-2<\frac{b}{a}<-\frac{1}{2}$.