我试图在Blazor wasm应用程序上运行https://github.com/JKorf/Binance.Net,而不是使用Azure函数,而是从客户端本身运行。
打开FetchData时遇到严重错误。
我的程序:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
//builder.Services.AddSingleton<IBinanceDataProvider, BinanceDataProvider>();
builder.Services.AddTransient<IBinanceClient>(x => new BinanceClient(new BinanceClientOptions
{
ApiCredentials = new ApiCredentials("API", "API"),
LogVerbosity = LogVerbosity.Debug,
LogWriters = new List<TextWriter> { Console.Out }
}));
builder.Services.AddSyncfusionBlazor();
await builder.Build().RunAsync();
}
FetchData.razor
@page "/fetchdata"
@inject HttpClient Http
@inject IBinanceClient BinanceClient
@page "/FormsValidation"
@code {
protected override async Task OnInitializedAsync()
{
using (var client = new BinanceClient())
{
try
{
var price = client.GetPriceAsync("BTCUSDT");
}
catch
{
Console.WriteLine("Error OnInitializedAsync");
}
}
}
我正在仔细检查我是否正确进行了依赖注入,但是我似乎处于死胡同。有什么想法可以尝试吗?