One workaround and two solutions i can think of (pick the one which suits you best):
Create your own Dictionary
MyDictionary<,> : Dictionary<,>
(with only a single parameterless ctor) andBind(typeof (IDictionary<,>)).To(typeof (MyDictionary<,>));
Adapt the binding to:
this.Bind(typeof(IDictionary<,>)).ToMethod(ctx => Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(ctx.GenericArguments)));
Adapt the binding to
this.Bind(typeof(IDictionary<,>)).ToConstructor(ctx => Activator.CreateInstance(typeof(Dictionary<,>).MakeGenericType(ctx.Context.GenericArguments)));
For the difference between .ToMethod()
and .ToConstructor()
see: What's the difference between .ToConstructor and .ToMethod in Ninject 3?