I am confused about why I am receiving "Ninject.ActivationException : Error Activating string No matching bindings are available, and the type is not self-bindable" in random bindings. If I leave the binding for IMedia in place it will throw the ActivationException, but if I use the CallbackProvider it works. All of these classes are structured the same with a few different properties. I'm confused as to why ILocationType, IMedia, and IFarmDataContext throw ActivationException while the others do not. Any ideas?
/******************************
* Core Types
******************************/
Bind<IFarmDataContext>().ToProvider(new CallbackProvider<IFarmDataContext>(delegate { return new FarmDataContext(); }));
//Media
Bind<IMedia>().To<Media>(); //blows up
//Bind<IMedia>().ToProvider(new CallbackProvider<IMedia>(delegate { return new Media(); }));
Bind<IMediaType>().To<MediaType>();
Bind<IMediaRelated>().To<MediaRelated>();
//Location
Bind<ILocation>().To<Location>();
Bind<ILocationType>().ToProvider(new CallbackProvider<ILocationType>(delegate { return new LocationType(); }));
Bind<ILocationDetail>().To<LocationDetail>();
Ninject doesn't have a binding for the "String key" to inject in the Media .ctor; When it tries to create a type that depends on Media, it doesn't know how to resolve the dependency and throws. For most types, Ninject would try to create something for you, but string and value types are not self-bindable as we don't have a good default value for them and it can cause havoc on types that use different conventions with primitives.
You need add a parameter value in your bindings (.WithContructorArgument("key", someValue)) or use some kind of provider (which you have done).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With