예제 #1
0
파일: Program.cs 프로젝트: DakaoBit/exDI
        static void Main(string[] args)
        {
            // 向 DI 容器註冊型別對應。
            MyDIContainer.Rigister <IMessageService, SMSService>();
            var demo = new Ch03.MyDIContainerV2.MainApp();

            demo.Login("nick", "1234");
        }
예제 #2
0
        static void Main(string[] args)
        {
            // 向 DI 容器註冊型別對應。
            MyDIContainer.Register <IMessageService, ShortMessageService>();

            var app = new MainApp();

            app.Login("michael", "1234");
        }
예제 #3
0
        public void Login(string userId, string pwd)
        {
            var msgService  = MyDIContainer.Resolve <IMessageService>();
            var authService = new AuthenticationService(msgService); // 注入相依物件。

            if (authService.TwoFactorLogin(userId, pwd))
            {
                // 與主題無關,故省略。
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: DakaoBit/exDI
        public void Login(string userId, string pwd)
        {
            var msgService  = MyDIContainer.Resolve <IMessageService>();
            var authService = new AuthenticationService(msgService); // 注入相依物件。

            if (authService.TwoFactorLogin(userId, pwd))
            {
                // 請使用者收信,然後回來輸入信中提示的驗證碼。
                string userInputToken = "123456";
                if (authService.VerifyToken(userInputToken))
                {
                    // 登入成功。
                }
            }
            // 登入失敗。
        }