private IServiceProvider CreateServiceProvider() { IServiceCollection services = new ServiceCollection(); string apiKey = ConfigurationManager.AppSettings.Get("financeApiKey"); services.AddSingleton <FinancialModelingPrepHttpClientFactory>(new FinancialModelingPrepHttpClientFactory(apiKey)); services.AddSingleton <SimpleTraderDbContextFactory>(); services.AddSingleton <IAuthenticationService, AuthenticationService>(); services.AddSingleton <IDataService <Account>, AccountDataService>(); services.AddSingleton <IAccountService, AccountDataService>(); services.AddSingleton <IStockPriceService, StockPriceService>(); services.AddSingleton <IBuyStockService, BuyStockService>(); services.AddSingleton <IMajorIndexService, MajorIndexService>(); services.AddSingleton <IPasswordHasher, PasswordHasher>(); services.AddSingleton <ISimpleTraderViewModelFactory, SimpleTraderViewModelFactory>(); services.AddSingleton <BuyViewModel>(); services.AddSingleton <PortfolioViewModel>(); services.AddSingleton <HomeViewModel>(services => new HomeViewModel( MajorIndexListingViewModel.LoadMajorIndexViewModel( services.GetRequiredService <IMajorIndexService>()))); services.AddSingleton <CreateViewModel <HomeViewModel> >(services => { return(() => services.GetRequiredService <HomeViewModel>()); }); services.AddSingleton <CreateViewModel <BuyViewModel> >(services => { return(() => services.GetRequiredService <BuyViewModel>()); }); services.AddSingleton <CreateViewModel <PortfolioViewModel> >(services => { return(() => services.GetRequiredService <PortfolioViewModel>()); }); services.AddSingleton <ViewModelDelegateRenavigator <HomeViewModel> >(); services.AddSingleton <CreateViewModel <LoginViewModel> >(services => { return(() => new LoginViewModel( services.GetRequiredService <IAuthenticator>(), services.GetRequiredService <ViewModelDelegateRenavigator <HomeViewModel> >())); }); services.AddSingleton <INavigator, Navigator>(); services.AddSingleton <IAuthenticator, Authenticator>(); services.AddSingleton <IAccountStore, AccountStore>(); services.AddScoped <MainViewModel>(); services.AddScoped <BuyViewModel>(); services.AddScoped <MainWindow>(s => new MainWindow(s.GetRequiredService <MainViewModel>())); return(services.BuildServiceProvider()); }
private IServiceProvider CreateServiceProvider() { IServiceCollection services = new ServiceCollection(); services.AddSingleton <IStockPriceService, StockPriceService>(); services.AddSingleton <IDataService <Account>, AccountDataService>(); services.AddSingleton <IAccountService, AccountDataService>(); services.AddSingleton <SimpleTraderDbContextFactory>(); services.AddSingleton <IBuyStockService, BuyStockService>(); services.AddSingleton <IMajorIndexService, MajorIndexService>(); services.AddSingleton <IAuthenticationService, AuthenticationService>(); services.AddSingleton <IPasswordHasher <string>, PasswordHasher <string> >(); services.AddSingleton <BuyViewModel>(); services.AddSingleton <PortfolioViewModel>(); services.AddSingleton <AssetSummaryViewModel>(); services.AddScoped <IAuthenticator, Authenticator>(); services.AddSingleton <ISimpleTraderViewModelFactory, SimpleTraderViewModelFactory>(); services.AddSingleton <Renavigator <HomeViewModel> >(); services.AddSingleton <HomeViewModel>(services => new HomeViewModel(MajorIndexListingViewModel .LoadMajorIndexViewModel( services.GetRequiredService <IMajorIndexService>()), services.GetRequiredService <AssetSummaryViewModel>())); services.AddSingleton <CreateViewModel <HomeViewModel> >(services => { return(() => services.GetRequiredService <HomeViewModel>()); }); services.AddSingleton <CreateViewModel <BuyViewModel> >(services => { return(() => services.GetRequiredService <BuyViewModel>()); }); services.AddSingleton <CreateViewModel <PortfolioViewModel> >(services => { return(() => services.GetRequiredService <PortfolioViewModel>()); }); services.AddSingleton <CreateViewModel <LoginViewModel> >(services => { return(() => new LoginViewModel( services.GetRequiredService <IAuthenticator>(), new Renavigator <HomeViewModel>( services.GetRequiredService <INavigator>(), services.GetRequiredService <CreateViewModel <HomeViewModel> >()))); }); services.AddSingleton <IAccountStore, AccountStore>(); services.AddSingleton <AssetStore>(); services.AddSingleton <INavigator, Navigator>(); services.AddSingleton <MainViewModel>(); return(services.BuildServiceProvider()); }
public ViewModelBase CreateViewModel(ViewType viewType) { switch (viewType) { case ViewType.Home: return(new HomeViewModel(MajorIndexListingViewModel.LoadMajorIndexViewModel(new MajorIndexService()))); break; case ViewType.Portfolio: return(new PortfolioViewModel()); break; default: throw new ArgumentException("The viewType does not have a VewModel.", "viewType"); } }
public void Execute(object parameter) { if (parameter is ViewType) { ViewType viewType = (ViewType)parameter; switch (viewType) { case ViewType.Home: _navigator.CurrentViewModel = new HomeViewModel(MajorIndexListingViewModel.LoadMajorIndexViewModel(new MajorIndexService())); break; case ViewType.Portfolio: _navigator.CurrentViewModel = new PortfolioViewModel(); break; default: break; } } }
public static IHostBuilder CreateHostBuilder(string[] args = null) { return(Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(c => { c.AddJsonFile("appsettings.json"); c.AddEnvironmentVariables(); }) .ConfigureServices((context, services) => { string apiKey = context.Configuration.GetValue <string>("FINANCE_API_KEY"); services.AddSingleton <FinancialModelingPrepHttpClientFactory>(new FinancialModelingPrepHttpClientFactory(apiKey)); string connectionString = context.Configuration.GetConnectionString("sqlite"); Action <DbContextOptionsBuilder> configureDbContext = o => o.UseSqlite(connectionString); services.AddDbContext <SimpleTraderDbContext>(configureDbContext); services.AddSingleton <SimpleTraderDbContextFactory>(new SimpleTraderDbContextFactory(configureDbContext)); services.AddSingleton <IAuthenticationService, AuthenticationService>(); services.AddSingleton <IDataService <Account>, AccountDataService>(); services.AddSingleton <IAccountService, AccountDataService>(); services.AddSingleton <IStockPriceService, StockPriceService>(); services.AddSingleton <IBuyStockService, BuyStockService>(); services.AddSingleton <ISellStockService, SellStockService>(); services.AddSingleton <IMajorIndexService, MajorIndexService>(); services.AddSingleton <IPasswordHasher, PasswordHasher>(); services.AddSingleton <ISimpleTraderViewModelFactory, SimpleTraderViewModelFactory>(); services.AddSingleton <BuyViewModel>(); services.AddSingleton <SellViewModel>(); services.AddSingleton <PortfolioViewModel>(); services.AddSingleton <AssetSummaryViewModel>(); services.AddSingleton <HomeViewModel>(services => new HomeViewModel( services.GetRequiredService <AssetSummaryViewModel>(), MajorIndexListingViewModel.LoadMajorIndexViewModel( services.GetRequiredService <IMajorIndexService>()))); services.AddSingleton <CreateViewModel <HomeViewModel> >(services => { return () => services.GetRequiredService <HomeViewModel>(); }); services.AddSingleton <CreateViewModel <BuyViewModel> >(services => { return () => services.GetRequiredService <BuyViewModel>(); }); services.AddSingleton <CreateViewModel <SellViewModel> >(services => { return () => services.GetRequiredService <SellViewModel>(); }); services.AddSingleton <CreateViewModel <PortfolioViewModel> >(services => { return () => services.GetRequiredService <PortfolioViewModel>(); }); services.AddSingleton <ViewModelDelegateRenavigator <LoginViewModel> >(); services.AddSingleton <CreateViewModel <RegisterViewModel> >(services => { return () => new RegisterViewModel( services.GetRequiredService <IAuthenticator>(), services.GetRequiredService <ViewModelDelegateRenavigator <LoginViewModel> >(), services.GetRequiredService <ViewModelDelegateRenavigator <LoginViewModel> >()); }); services.AddSingleton <ViewModelDelegateRenavigator <HomeViewModel> >(); services.AddSingleton <ViewModelDelegateRenavigator <RegisterViewModel> >(); services.AddSingleton <CreateViewModel <LoginViewModel> >(services => { return () => new LoginViewModel( services.GetRequiredService <IAuthenticator>(), services.GetRequiredService <ViewModelDelegateRenavigator <HomeViewModel> >(), services.GetRequiredService <ViewModelDelegateRenavigator <RegisterViewModel> >()); }); services.AddSingleton <INavigator, Navigator>(); services.AddSingleton <IAuthenticator, Authenticator>(); services.AddSingleton <IAccountStore, AccountStore>(); services.AddSingleton <AssetStore>(); services.AddScoped <MainViewModel>(); services.AddScoped <MainWindow>(s => new MainWindow(s.GetRequiredService <MainViewModel>())); })); }
private static HomeViewModel CreateHomeViewModel(IServiceProvider services) { return(new HomeViewModel( services.GetRequiredService <AssetSummaryViewModel>(), MajorIndexListingViewModel.LoadMajorIndexViewModel(services.GetRequiredService <IMajorIndexService>()))); }
public HomeViewModel(MajorIndexListingViewModel majorIndexViewModel) { MajorIndexListingViewModel = majorIndexViewModel; }
public LoadMajorIndexesCommand(MajorIndexListingViewModel majorIndexListingViewModel, IMajorIndexService majorIndexService) { _majorIndexListingViewModel = majorIndexListingViewModel; _majorIndexService = majorIndexService; }
public HomeViewModel(AssetSummaryViewModel assetSummaryViewModel, MajorIndexListingViewModel majorIndexListingViewModel) { AssetSummaryViewModel = assetSummaryViewModel; MajorIndexListingViewModel = majorIndexListingViewModel; }
public HomeViewModel(MajorIndexListingViewModel majorIndexListingViewModel, AssetSummaryViewModel assetSummaryViewModel) { MajorIndexListingViewModel = majorIndexListingViewModel; AssetSummaryViewModel = assetSummaryViewModel; }