static void TestGenicClass() { IServiceProvider serviceProvider = new ServiceCollection() .AddTransient(typeof(ISay <>), typeof(Say <>)) .BuildServiceProvider(); ISay <string> say = serviceProvider.GetService <ISay <string> >(); }
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()); } }
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()); }
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!"); } }
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); } }
public string GetSayThing(ISay say) { return(say.GetSayThing()); }
public HomeController(ICodeDiServiceProvider serviceProvider) { _say = serviceProvider.GetService <ISay>("*Chinese"); }
public Animal([DefaultValue("i'm ok!")] string s, ISay key) { _words = s; _animal = key; }