I shipped a small update to SpecsFor yesterday.  This update exposes the underlying mocking container to behaviors that are registered using the compositional context API.

[more]

Now you can do things like modify the container’s configuration from any behavior class.  We could specify that any dependency on some type should be resolved with a concrete type instead of a mocked instance, like so:

public interface IDatabaseSpecs : ISpecs
{
    //Stuff...
}

public class DatabaseFactory : Behavior<IDatabaseSpecs>
{
    public override void SpecInit(IDatabaseSpecs instance)
    {
        instance.MockContainer.Configure(cfg =>
        {
            cfg.For<AppDbContext>().Use<TestAppDbContext>();
        });
    }
}

There’s one “gotcha!” though: at runtime, the “instance” passed to the behavior is guaranteed to implement the ISpecs interface (since it will always be an instance of SpecsFor<T>), but that may not be obvious at compile time.  If our IDatabaseSpecs class did not implement the ISpecs interface itself, then you’d have to cast the instance to access the container, like so:

public interface IDatabaseSpecs
{
    //Stuff
}

public class DatabaseFactory : Behavior<IDatabaseSpecs>
{
    public override void SpecInit(IDatabaseSpecs instance)
    {
        ((ISpecs)instance).MockContainer.Configure(cfg =>
        {
            cfg.For<AppDbContext>().Use<TestAppDbContext>();
        });
    }
}

As usual, please create an issue over at Github if you run into any problems.