public Handler(IUserRepository repository, SimpleTokenProvider tokenProvider, IDateTimeProvider dateTimeProvider, IMapper mapper) { this._userRepository = repository; _tokenProvider = tokenProvider; _dateTimeProvider = dateTimeProvider; _mapper = mapper; }
private void InitializeProviders() { MailerMock = new Mock <IMailer>(); LoggerMock = new Mock <ILogger>(); DateTimeProvider = new DateTimeProvider(); EmailProvider = new EmailProvider(MailerMock.Object); SimpleTokenProvider = new SimpleTokenProvider(TimeSpan.FromDays(30), HealthyJuicesConstants.LOCAL_ACCESS_TOKEN_SECRET); CurrentUserProviderMock = new Mock <ICurrentUserProvider>(); ServiceCollection.AddTransient(x => MailerMock.Object); ServiceCollection.AddTransient(x => LoggerMock.Object); ServiceCollection.AddTransient(x => DateTimeProvider); ServiceCollection.AddTransient(x => EmailProvider); ServiceCollection.AddTransient(x => SimpleTokenProvider); }
private async void App_OnStartup(object sender, StartupEventArgs e) { using (var container = ApplicationContainerFactory.Create()) { IViewService viewService = container.Resolve <IViewService>(); var logonViewModel = container.Resolve <LogonDialogViewModel>(); var settings = container.Resolve <ISettings>(); if (settings.ShouldRememberToken) { logonViewModel.Token = settings.Token; } logonViewModel.ShouldRememberToken = settings.ShouldRememberToken; while (true) { try { if (viewService.ShowDialog(logonViewModel) == true) { //Create a temporary token provider var tokenProvider = new SimpleTokenProvider(logonViewModel.Token); //Use a temp client to update the token / verify the current token var tempClient = new ResinApiClient(tokenProvider, logonViewModel.ApiAddress); //Get the new token (this also verifies the old one) string newToken = await tempClient.WhoamiAsync(); settings.ShouldRememberToken = logonViewModel.ShouldRememberToken; if (logonViewModel.ShouldRememberToken) { settings.Token = newToken; } using (var childScope = container.BeginLifetimeScope(builder => { builder.RegisterInstance(tokenProvider).As <ITokenProvider>(); })) { //Create a new client var client = new ResinApiClient(new SimpleTokenProvider(newToken), logonViewModel.ApiAddress); //Create the view model var mainViewModel = childScope.Resolve <MainViewModel>(new TypedParameter(typeof(ResinApiClient), client)); //Finally - we can start up the real thing! viewService.ShowDialog(mainViewModel); } return; } //The user cancelled. Exit the application. return; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } } } }