Skip to content

Commit

Permalink
- rename protected members in AbstractProvider
Browse files Browse the repository at this point in the history
- rename `private static` member in `DefaultServiceProvider`
- use `GetRequiredService` instead of `GetService` and throwing custom exception
- use 1.0.4 version of `poolz.finance.csharp.contracts` package
  • Loading branch information
ArdenHide committed Jun 26, 2024
1 parent 9e12262 commit b031026
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/MetaDataAPI/DefaultServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace MetaDataAPI;

public static class DefaultServiceProvider
{
private static readonly Lazy<IServiceProvider> lazyInstance = new(() =>
private static readonly Lazy<IServiceProvider> LazyInstance = new(() =>
{
var serviceCollection = new ServiceCollection();

Expand All @@ -19,5 +19,5 @@ public static class DefaultServiceProvider
return serviceCollection.BuildServiceProvider();
});

public static IServiceProvider Instance => lazyInstance.Value;
public static IServiceProvider Instance => LazyInstance.Value;
}
2 changes: 1 addition & 1 deletion src/MetaDataAPI/LambdaFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public LambdaFunction()
public LambdaFunction(IServiceProvider serviceProvider)
{
_serviceProvider = DefaultServiceProvider.Instance;
_chainManager = serviceProvider.GetService<IChainManager>() ?? throw new ArgumentException($"Service '{nameof(IChainManager)}' is required.");
_chainManager = serviceProvider.GetRequiredService<IChainManager>();
}

public LambdaResponse FunctionHandler(LambdaRequest request, ILambdaContext lambdaContext)
Expand Down
2 changes: 1 addition & 1 deletion src/MetaDataAPI/MetaDataAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<PackageReference Include="Net.Urlify" Version="1.0.1" />
<PackageReference Include="TLY.ShortUrl" Version="1.0.1" />
<PackageReference Include="Utils.EnvironmentManager" Version="3.0.4" />
<PackageReference Include="poolz.finance.csharp.contracts" Version="1.0.3" />
<PackageReference Include="poolz.finance.csharp.contracts" Version="1.0.4" />
</ItemGroup>
</Project>
12 changes: 6 additions & 6 deletions src/MetaDataAPI/Providers/AbstractProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace MetaDataAPI.Providers;

public abstract class AbstractProvider : Urlify
{
protected readonly IErc20Provider erc20Provider;
protected readonly ITlyContext tlyContext;
protected readonly IErc20Provider Erc20Provider;
protected readonly ITlyContext TlyContext;

public IEnumerable<BasePoolInfo> FullData { get; }
public BasePoolInfo PoolInfo { get; }
Expand Down Expand Up @@ -49,14 +49,14 @@ protected AbstractProvider(BasePoolInfo[] poolsInfo, ChainInfo chainInfo)
protected AbstractProvider(BasePoolInfo[] poolsInfo, ChainInfo chainInfo, IServiceProvider serviceProvider)
: base((string)Environments.NFT_HTML_ENDPOINT.Get())
{
erc20Provider = serviceProvider.GetService<IErc20Provider>() ?? throw new ArgumentException($"Service '{nameof(IErc20Provider)}' is required.");
tlyContext = serviceProvider.GetService<ITlyContext>() ?? throw new ArgumentException($"Service '{nameof(ITlyContext)}' is required.");
Erc20Provider = serviceProvider.GetRequiredService<IErc20Provider>() ?? throw new ArgumentException($"Service '{nameof(IErc20Provider)}' is required.");
TlyContext = serviceProvider.GetRequiredService<ITlyContext>() ?? throw new ArgumentException($"Service '{nameof(ITlyContext)}' is required.");

FullData = poolsInfo;
PoolInfo = poolsInfo[0];
ChainInfo = chainInfo;

Erc20Token = erc20Provider.GetErc20Token(chainInfo, PoolInfo.Token);
Erc20Token = Erc20Provider.GetErc20Token(chainInfo, PoolInfo.Token);

PoolId = PoolInfo.PoolId;
Name = PoolInfo.Name;
Expand All @@ -83,7 +83,7 @@ private string GetImage()
{
var url = new UrlifyProvider(this).BuildUrl();
var description = $"ChainId: {ChainInfo.ChainId}, PoolId: {PoolId}, ProviderName: {Name}, VaultId: {VaultId}";
return tlyContext.GetShortUrlAsync(url, description)
return TlyContext.GetShortUrlAsync(url, description)
.GetAwaiter()
.GetResult()
.ShortUrl;
Expand Down
4 changes: 2 additions & 2 deletions src/MetaDataAPI/Providers/CollateralProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public CollateralProvider(BasePoolInfo poolInfo, ChainInfo chainInfo, IServicePr
public CollateralProvider(BasePoolInfo[] poolsInfo, ChainInfo chainInfo, IServiceProvider serviceProvider)
: base(poolsInfo, chainInfo, serviceProvider)
{
MainCoin = erc20Provider.GetErc20Token(chainInfo, poolsInfo[0].Token);
Erc20Token = erc20Provider.GetErc20Token(chainInfo, poolsInfo[2].Token);
MainCoin = Erc20Provider.GetErc20Token(chainInfo, poolsInfo[0].Token);
Erc20Token = Erc20Provider.GetErc20Token(chainInfo, poolsInfo[2].Token);
FinishTime = PoolInfo.Params[1];
Rate = Web3.Convert.FromWei(PoolInfo.Params[2], 21);

Expand Down

0 comments on commit b031026

Please sign in to comment.