The Func-Auto binding to Func-Factory is a feature of Ninject.Extensions.Factory. See source:
FuncModule.cs
If you create a specific binding for Func<T, T>
it will still override the generic binding created by FuncModule
. But as you noticed, there won't be any exceptions if you don't create that specific binding.
The simplest way to get rid of the default (open) binding is getting rid of the Factory extension.
But that is probably a bit drastic. What you can also do instead, is disabling Auto-Extension loading:
var kernel = new StandardKernel(new NinjectSettings {LoadExtensions = false});
Then you'll have to load extensions dynamically - this is done by loading their NinjectModule
implementations. For example:
IKernel.Load<FuncModule>();
Of course the FuncModule
you don't want to load, we're doing all this to get rid of it. But you'll have to do it for all the other extension modules you actually want.
Finally you'll have to create all Factory extension bindings that you need:
if (!this.Kernel.GetBindings(typeof(Func<IContext, IResolutionRoot>)).Any())
{
this.Bind<Func<IContext, IResolutionRoot>>().ToMethod(ctx => context => context.Kernel);
}
this.Bind<FuncProvider>().ToSelf().InSingletonScope();
this.Bind<IFunctionFactory>().To<FunctionFactory>();
this.Bind<IInstanceProvider>().To<StandardInstanceProvider>();
#if !SILVERLIGHT_20 && !WINDOWS_PHONE && !NETCF_35
this.Bind<IInterceptor>().To<FactoryInterceptor>()
.When(request => typeof(IFactoryProxy).IsAssignableFrom(request.Target.Member.ReflectedType));
#endif
Note:
If you are actually using the Func-Factories, i would recommend "ignoring" the issue. You now know where to look, should the issue ever arise again.
If this is an isolated problem, you could also replace your Func<,>
by an interface, making things more explicit (clean code).
Of course this is not a perfect solution by any means. It's just one of the tough choices one has to make ;-)