Exemplo n.º 1
0
        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()");
        }