示例#1
0
        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);
        }
示例#2
0
 public void None_RemovesInjection()
 {
     Inject.Type <DataLayer>().Into <AppLayer>();
     Inject.None.Into <AppLayer>();
     Assert.Throws <InvalidOperationException>(() => {
         Injection <DataLayer> .For <AppLayer>();
     });
 }
示例#3
0
        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));
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
 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));
 }
示例#7
0
 public ForTypeName(Injection injection, string typeName) : base(injection, typeName)
 {
     TypeName = typeName ?? throw new ArgumentNullException(nameof(typeName));
 }
示例#8
0
 public ForType(Injection injection, Type type) : base(injection, type)
 {
     Type = type ?? throw new ArgumentNullException(nameof(type));
 }
示例#9
0
 public InjectionRecipient(Injection injection, object recipient)
 {
     Injection = injection;
     Recipient = recipient ?? throw new ArgumentNullException(nameof(recipient));
 }
示例#10
0
 public void Add(Injection injection, object recipient)
 {
     List.Add(InjectionRecipient.For(injection, recipient));
 }