Ejemplo n.º 1
0
        // This is the best DI factory sample.
        public static void Run()
        {
            Console.WriteLine($"开始运行{nameof(Demo5)}");
            ContainerBuilder cb = new ContainerBuilder();

            cb.RegisterModule <CoreModule>();
            cb.RegisterModule <SmsCoreModule>();
            cb.RegisterModule <ConsoleSmsModule>();
            cb.RegisterModule <HttpApiSmsModule>();
            cb.RegisterInstance(new SmsConfig
            {
                SmsSenderType = SmsSenderType.HttpAPi
            }).As <SmsConfig>();

            IContainer container = cb.Build();

            IUserBll userBll = container.Resolve <IUserBll>();

            Console.WriteLine(userBll.GetHashCode());
            bool login = userBll.Login("12345678901", "Password");

            Console.WriteLine(login);

            login = userBll.Login("10987654321", "ytrewq");
            Console.WriteLine(login);
            Console.WriteLine($"结束运行{nameof(Demo5)}");
        }