示例#1
0
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <Class1>();
            //builder.RegisterType<Class2>();
            //builder.RegisterType<Class3>();
            using (IContainer container = builder.Build())
            {
                Class1 cls1 = container.Resolve <Class1>();
                cls1.print();

                Class2 cls2 = container.ResolveOptional <Class2>();
                if (null != cls2)
                {
                    cls2.print();
                }
                else
                {
                    Console.WriteLine("cls2 is null ...");
                }

                Class3 cls3 = null;
                if (container.TryResolve <Class3>(out cls3))
                {
                    cls3.print();
                }
                else
                {
                    Console.WriteLine("cls3 is null ...");
                }
            }

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            int opcion;

            Console.WriteLine("digite una opcion [1-6]");
            opcion = System.Convert.ToInt32(Console.ReadLine());
            switch (opcion)
            {
            case 1:
                Class1 c1 = new Class1();
                c1.eje1();
                break;

            case 2:
                Class2 c2 = new Class2();
                c2.eje2();
                break;

            case 3:
                Class3 c3 = new Class3();
                c3.eje3();
                break;

            case 4:
                Class4 c4 = new Class4();
                c4.eje1();
                break;

            case 5:
                Class5 c5 = new Class5();
                c5.eje1();
                break;

            case 6:
                Class6 c6 = new Class6();
                c6.eje1();
                break;

            default:
                break;
            }
            Console.ReadKey();
        }