本文整理汇总了C#中IModule.Get方法的典型用法代码示例。如果您正苦于以下问题:C# IModule.Get方法的具体用法?C# IModule.Get怎么用?C# IModule.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IModule
的用法示例。
在下文中一共展示了IModule.Get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DemoInferables
private static void DemoInferables(IModule module)
{
ShowConsoleHeader(module);
// Here we are getting an inferred type that matches interface IFoo based on the namespace bindings for this module.
var foo = module.Get<IFoo>();
foo.Dump("Value for foo");
// This method resolves the inferred on finding the match patten foo2 for Interface type IFoo.
var foo2 = module.Get<IFoo>("foo2");
foo.Dump("Value for foo2");
// Here we are getting foo again- performance very good this time around since all type generation il code has been cached.
var fooAgain = module.Get<IFoo>();
fooAgain.Dump("Value for fooAgain");
// Here we are mapping explicitly to a Foo type, choosing the appropriate constructor and infering dependencies.
var explicitFoo = module.GetExplicit<Foo>();
explicitFoo.Dump("Value of explicit foo");
ShowFactoryTestsHeader();
// Here we are binding to a custom factory interface, which will automatically generate a type for this factory, cache the it, and instantiate it.
var factory = module.GetFactory<IFactory>();
factory.GetFoo().Dump("Value for GetFoo()");
factory.GetFoo1().Dump("Value for GetFoo1()");
factory.GetFoo2().Dump("Value for GetFoo2()");
factory.GetFoo3().Dump("Value for GetFoo3()");
factory.GetFoo4().Dump("Value for GetFoo4()");
factory.GetFoo5().Dump("Value for GetFoo5()");
factory.GetFoo6().Dump("Value for GetFoo6()");
}