当前位置: 首页>>代码示例>>C#>>正文


C# IModule.GetExplicit方法代码示例

本文整理汇总了C#中IModule.GetExplicit方法的典型用法代码示例。如果您正苦于以下问题:C# IModule.GetExplicit方法的具体用法?C# IModule.GetExplicit怎么用?C# IModule.GetExplicit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IModule的用法示例。


在下文中一共展示了IModule.GetExplicit方法的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()");
        }
开发者ID:nmuhonen,项目名称:Inferables-For-CLR,代码行数:32,代码来源:Program.cs


注:本文中的IModule.GetExplicit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。