, IsRuntimeFlag ( , ), :
if (IsRuntimeFlag)
{
container.Register<I, A>();
}
else
{
container.Register<I, B>();
}
:
container.Register(typeof(I), IsRuntimeFlag ? typeof(A) : typeof(B));
, , composite, , :
public sealed class RuntimeFlagIComposite : I
{
private readonly A a;
private readonly B b;
public RuntimeFlagIComposite(A a, B b) {
this.a = a;
this.b = b;
}
void I.Method() => this.Instance.Method();
private I Instance => IsRuntimeFlag ? this.a : this.b;
}
A B, :
container.Register<I, RuntimeFlagIComposite>();
A B , ( ), . :
container.Register<A>(Lifestyle.Singleton);
container.Register<B>(Lifestyle.Scoped);
I A B:
public class RuntimeFlagIComposite : I
{
private I a;
private I b;
public RuntimeFlagIComposite(I a, I b)
{
this.a = a;
this.b = b;
}
}
I . , , :
container.Register<I, RuntimeFlagIComposite>();
container.RegisterConditional<I, A>(c => c.Consumer.Target.Name == "a");
container.RegisterConditional<I, B>(c => c.Consumer.Target.Name == "b");