Я получаю сообщение об ошибке
Не удалось вывести один или несколько параметров
параметра сеанса при запуске запрос.
Код: Выделить всё
dataSourceПараметр Код:
Код: Выделить всё
using Npgsql;
using System.Collections.Concurrent;
using System.Numerics;
using Webserver;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton();
builder.Services.AddSingleton(provider =>
{
return NpgsqlDataSource.Create("Host=localhost;Username=postgres;Password=postgres;Database=postgres");
});
var app = builder.Build();
app.UseHttpsRedirection();
app.Use(async (context, next) =>
{
Console.WriteLine("Middleware");
ConcurrentDictionary sessions = context.RequestServices.GetRequiredService();
NpgsqlDataSource dataSource = context.RequestServices.GetRequiredService();
Console.WriteLine(sessions.Count);
await next();
});
app.MapPost("/test", async (NpgsqlDataSource dataSource, LoginData credentials, ConcurrentDictionary sessions) =>
{
Console.WriteLine("Test");
return "OK";
});
app.Run();
Код: Выделить всё
System.InvalidOperationException: Failure to infer one or more parameters.
Below is the list of parameters that we found:
Parameter | Source
---------------------------------------------------------------------------------
dataSource | Services (Inferred)
credentials | Body (Inferred)
sessions | UNKNOWN
Did you mean to register the "UNKNOWN" parameters as a Service?
Код: Выделить всё
app.MapPost("/test", async (NpgsqlDataSource dataSource, [FromServices] ConcurrentDictionary sessions) =>
{
Console.WriteLine("Test");
Console.WriteLine(sessions.Count);
return "OK";
});
Код: Выделить всё
System.InvalidOperationException: No service for type 'System.Collections.Concurrent.ConcurrentDictionary`2[System.Guid,System.Numerics.BigInteger]' has been registered.
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at lambda_method2(Closure, Object, HttpContext)
at Program.c.d.MoveNext()
Подробнее здесь: https://stackoverflow.com/questions/797 ... -singleton
Мобильная версия