public void Type_InstantiatesType() { Inject.None.Into <AppLayer>(); Inject.Type <DataLayer>().Into <AppLayer>(); var inst = Injection <DataLayer> .For <AppLayer>(); Assert.That(inst, Is.Not.Null); }
public void None_RemovesInjection() { Inject.Type <DataLayer>().Into <AppLayer>(); Inject.None.Into <AppLayer>(); Assert.Throws <InvalidOperationException>(() => { Injection <DataLayer> .For <AppLayer>(); }); }
public void This_ProvidesSameInstanceToType() { var data = new DataLayer(); Inject.This(data).Into <AppLayer>(); var inst = Injection <DataLayer> .For <AppLayer>(); Assert.That(inst, Is.SameAs(data)); }
public void Type_InstantiatesNewInstance() { Inject.None.Into <AppLayer>(); Inject.Type <DataLayer>().Into <AppLayer>(); var inst1 = Injection <DataLayer> .For <AppLayer>(); var inst2 = Injection <DataLayer> .For <AppLayer>(); Assert.That(inst2, Is.Not.SameAs(inst1)); }
public void Into_UsesTypeName() { var obj1 = new InvisibleType.Controller(); var subject = new Injection <InvisibleType.Controller>(() => obj1); subject.Into("InvisibleType"); var obj2 = Injection <InvisibleType.Controller> .For(new InvisibleType()); Assert.That(obj2, Is.SameAs(obj1)); }
public static InjectionRecipient For(Injection injection, object recipient) { if (recipient is Type t) { return(new ForType(injection, t)); } if (recipient is string s) { return(new ForTypeName(injection, s)); } return(new InjectionRecipient(injection, recipient)); }
public ForTypeName(Injection injection, string typeName) : base(injection, typeName) { TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName)); }
public ForType(Injection injection, Type type) : base(injection, type) { Type = type ?? throw new ArgumentNullException(nameof(type)); }
public InjectionRecipient(Injection injection, object recipient) { Injection = injection; Recipient = recipient ?? throw new ArgumentNullException(nameof(recipient)); }
public void Add(Injection injection, object recipient) { List.Add(InjectionRecipient.For(injection, recipient)); }