/// <summary> /// Creates an FMP API Client with all dependencies already wired up. /// If you do want to use DI please see <see cref="DependencyInjectionExtensions.AddFinancialModelingPrepApiClient(IServiceCollection, FinancialModelingPrepOptions)"/> /// </summary> /// <param name="options"><see cref="FinancialModelingPrepOptions"/></param> /// <returns>An instance of <see cref="IFinancialModelingPrepApiClient"/></returns> public static IFinancialModelingPrepApiClient CreateClient(FinancialModelingPrepOptions options) { var services = new ServiceCollection(); services.AddFinancialModelingPrepApiClient(options); var provider = services.BuildServiceProvider(); return(provider.GetRequiredService <IFinancialModelingPrepApiClient>()); }
/// <summary> /// Adds the <see cref="IFinancialModelingPrepApiClient"/> to the services. /// This package does not override any existing registrations. /// </summary> /// <param name="services">DI Service Collection</param> /// <param name="options">FMP Options <see cref="FinancialModelingPrepOptions"/> if left as null it will use the default options and default API Key</param> public static void AddFinancialModelingPrepApiClient(this IServiceCollection services, FinancialModelingPrepOptions options = null) { services.TryAddSingleton(options ?? new FinancialModelingPrepOptions()); services.AddLogging(); services.AddHttpClient <FinancialModelingPrepHttpClient>(client => client.BaseAddress = new Uri("https://financialmodelingprep.com/api/")); services.TryAddSingleton <IFinancialModelingPrepApiClient, FinancialModelingPrepApiClient>(); services.TryAddTransient <ICompanyValuationProvider, CompanyValuationProvider>(); services.TryAddTransient <IMarketIndexesProvider, MarketIndexesProvider>(); services.TryAddTransient <IAdvancedDataProvider, AdvancedDataProvider>(); services.TryAddTransient <ICalendarsProvider, CalendarsProvider>(); services.TryAddTransient <IInstitutionalFundProvider, InstitutionalFundProvider>(); services.TryAddTransient <IStockTimeSeriesProvider, StockTimeSeriesProvider>(); }