Skip to content

Commit 8a6e851

Browse files
committed
Add factory method for those who don't want to use DI
1 parent 9e0408c commit 8a6e851

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace MatthiWare.FinancialModelingPrep
4+
{
5+
/// <summary>
6+
/// Exposes factory methods to easily create clients without using dependency injection.
7+
/// If you do want to use DI please see <see cref="DependencyInjectionExtensions.AddFinancialModelingPrepApiClient(IServiceCollection, FinancialModelingPrepOptions)"/>
8+
/// </summary>
9+
public static class FinancialModelingPrepApiClientFactory
10+
{
11+
/// <summary>
12+
/// Creates an FMP API Client with all dependencies already wired up.
13+
/// If you do want to use DI please see <see cref="DependencyInjectionExtensions.AddFinancialModelingPrepApiClient(IServiceCollection, FinancialModelingPrepOptions)"/>
14+
/// </summary>
15+
/// <param name="options"><see cref="FinancialModelingPrepOptions"/></param>
16+
/// <returns>An instance of <see cref="IFinancialModelingPrepApiClient"/></returns>
17+
public static IFinancialModelingPrepApiClient CreateClient(FinancialModelingPrepOptions options)
18+
{
19+
var services = new ServiceCollection();
20+
21+
services.AddFinancialModelingPrepApiClient(options);
22+
23+
var provider = services.BuildServiceProvider();
24+
25+
return provider.GetRequiredService<IFinancialModelingPrepApiClient>();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)