I have 2 different concrete objects, lets save ConcreteOne and ConcreteTwo. Each of these implement an interface ILooseyGoosey. I would like ninject to call a different method depending on the attribute on that method.
This is what I have so far:
public class ConcreteOne : ILooseyGoosey
{
public void SomeMethod() { };
}
public class ConcreteTwo : ILooseyGoosey
{
public void SomeMethod() { } ;
}
public interface ILooseyGoosey
{
[CallConcreteTwo()]
void SomeMethod();
}
This is what I have defined in my Ninject module:
public override void Load()
{
Bind<ILooseyGoosey>().To<ConcreteOne>().InjectMethodsWhere(mi => mi.GetCustomAttributes(true).Where(a => a.GetType() == typeof(CallConcreteTwoAttribute)).Count() == 0);
Bind<ILooseyGoosey>().To<ConcreteTwo>().InjectMethodsWhere(mi => mi.GetCustomAttributes(true).Where(a => a.GetType() == typeof(CallConcreteTwoAttribute)).Count() > 0);
}
I get the error of:
System.NotSupportedException : Error registering service ILooseyGoosey: Multiple default bindings declared for service. Found 2 default bindings: