Esempio n. 1
0
 static void TestGenicClass()
 {
     IServiceProvider serviceProvider = new ServiceCollection()
                                        .AddTransient(typeof(ISay <>), typeof(Say <>))
                                        .BuildServiceProvider();
     ISay <string> say = serviceProvider.GetService <ISay <string> >();
 }
Esempio n. 2
0
        public void Attribute_Proxy_Inject_Proxy_Invoker()
        {
            using (var injector = Injector.Create())
            {
                injector.RegisterType <ISay, CustomProxyAttributeSayHello>();

                ISay o = injector.CreateInstance <ISay>();

                Assert.IsInstanceOfType(o, typeof(InjectProxyInvokerSayWorld));
                Assert.AreEqual("Hello World", o.Say());
            }
        }
Esempio n. 3
0
        public void Register_Type_Inject_Constructor()
        {
            var injector = Injector.Create();

            injector.RegisterType <ISay, CustomSay>(new InjectConstructor("Hello"));

            ISay o = injector.CreateInstance <ISay>();

            Assert.IsNotNull(o);
            Assert.IsInstanceOfType(o, typeof(CustomSay));
            Assert.AreEqual("Hello", o.Say());
        }
Esempio n. 4
0
        public void Register_Proxy_Inject_Target()
        {
            using (var injector = Injector.Create())
            {
                injector.RegisterType <ISay, SayHello>();
                injector.RegisterProxy <ISay, InjectTargetSayWorld>();

                ISay o = injector.CreateInstance <ISay>();

                Assert.IsInstanceOfType(o, typeof(InjectTargetSayWorld));
                Assert.AreEqual("Hello World", o.Say());
            }
        }
        public static void Print(ISay say)
        {
            System.Reflection.MemberInfo info = say.GetType();
            BlockAttribute att = (BlockAttribute)Attribute.GetCustomAttribute(info, typeof(BlockAttribute));

            if (att.Level == Level.Yes)
            {
                Console.WriteLine(say.GetType() + ": " + say.Say());
            }
            else
            {
                Console.WriteLine(say.GetType() + ": " + "I Love the contry!");
            }
        }
Esempio n. 6
0
        public void Calculate(string aExpr, ISay aSayer)
        {
            int      result = 0;
            BasicSay sayer  = aSayer as BasicSay;

            try {
                result = GetPlus(aExpr);
                if (result == -1)
                {
                    sayer.BadCalcSay();
                    return;
                }
                sayer.GoodCalcSay(result);
            } catch (Exception e) {
                sayer.BadCalcSay();
                sayer.Say(e.StackTrace);
            }
        }
Esempio n. 7
0
 public string GetSayThing(ISay say)
 {
     return(say.GetSayThing());
 }
Esempio n. 8
0
 public HomeController(ICodeDiServiceProvider serviceProvider)
 {
     _say = serviceProvider.GetService <ISay>("*Chinese");
 }
Esempio n. 9
0
 public Animal([DefaultValue("i'm ok!")] string s, ISay key)
 {
     _words  = s;
     _animal = key;
 }