After my post yesterday Krzysztof Kozmic (@kkozmic) messaged me saying I should use the Castle DictionaryAdapterFactory instead.

For the record Krzysztof has a great series of posts on DynamicProxy and was also very helpful answering a specific question of mine yesterday.

Anyway this is great news! I can do the same thing only referencing one assembly. The DictionaryAdapterFactory returns an object that passes all my tests from yesterday and slides staight into the model binder.

public class FakeInterfaceModelBinder : DefaultModelBinder
{
    protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
    {
        Dictionary<string, object> dictionary = new Dictionary<string,object>();
        return new DictionaryAdapterFactory().GetAdapter(modelType,dictionary);
    }
}

It was fun playing with DynamicProxy yesterday, but I did think it might not have been a good idea for a model binder. I'm glad I was pointed in the right direction.

Cheers Krzysztof!