first:
Please post the exact ActivationException message + Stacktrace.
Most likely the binding for IService2
is missing or there is a circular dependency.
second: Use a binding generator:
public override void Load()
{
this.Bind(x => x
.FromThisAssembly()
.SelectAllClasses()
.InheritedFrom<BaseClass>()
.BindWith<ToSelfProxyBindingGenerator>()
.Configure(binding => binding.InSingletonScope()));
}
public class ToSelfProxyBindingGenerator : IBindingGenerator
{
public IEnumerable<IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(Type type, IBindingRoot bindingRoot)
{
yield return bindingRoot
.Bind(type)
.ToMethod(ctx => fac.CreateProxy(type));
}
}
Also note that the singleton scope can be defined by the IBindingGenerator
or @ convention using the .Configure(..)
method.
General Questions:
- You are correct, but i can't tell you the exact reasoning behind it.
- No it is perfectly fine to put conventions into different modules. We are doing this too and it works out perfectly.