Skip to content

Commit 106749f

Browse files
committed
fix plugin logger and don't create handler when endpoints is zero
1 parent 48e5e1c commit 106749f

5 files changed

Lines changed: 49 additions & 4 deletions

File tree

NpgsqlRest/MiddlewareExtension.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public static IApplicationBuilder UseNpgsqlRest(this IApplicationBuilder builder
5151
var dict = BuildDictionary(builder, options, logger);
5252
var serviceProvider = builder.ApplicationServices;
5353

54+
if (dict.Count == 0)
55+
{
56+
return builder;
57+
}
58+
5459
builder.Use(async (context, next) =>
5560
{
5661
var path = context.Request.Path.ToString();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"ConnectionStrings": {
3-
"Default": "Host=127.0.0.1;Port=5432;Database=npgsql_rest_test;Username=postgres;Password=postgres"
3+
//"Default": "Host=127.0.0.1;Port=5432;Database=npgsql_rest_test;Username=postgres;Password=postgres"
44
}
55
}

NpgsqlRestTestWebApi/npgsql_rest_test.http

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ GET {{host}}/api/case-get-int-params-array?a=1&a=2&a=3
108108

109109
###
110110

111+
// function public.case_get_long_table1(
112+
// _records integer
113+
// )
114+
// returns table(
115+
// int_field integer,
116+
// text_field text
117+
// )
118+
GET {{host}}/api/case-get-long-table1?records=1
119+
120+
###
121+
111122
// function public.case_get_multi_params1(
112123
// _smallint smallint,
113124
// _integer integer,

plugins/NpgsqlRest.HttpFiles/HttpFile.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Text;
2-
using Microsoft.Extensions.Options;
32
using Npgsql;
43

54
namespace NpgsqlRest.HttpFiles;
@@ -19,8 +18,23 @@ public HttpFile() : this (new HttpFileOptions()) { }
1918

2019
public void Setup(IApplicationBuilder builder, ILogger? logger, NpgsqlRestOptions options)
2120
{
21+
if (builder is WebApplication app)
22+
{
23+
var factory = app.Services.GetRequiredService<ILoggerFactory>();
24+
if (factory is not null)
25+
{
26+
_logger = factory.CreateLogger(options.LoggerName ?? typeof(HttpFile).Namespace ?? "NpgsqlRest.HttpFiles");
27+
}
28+
else
29+
{
30+
_logger = app.Logger;
31+
}
32+
}
33+
else
34+
{
35+
_logger = logger;
36+
}
2237
_builder = builder;
23-
_logger = logger;
2438
}
2539

2640
public void Handle(Routine routine, RoutineEndpoint endpoint)

plugins/NpgsqlRest.TsClient/TsClient.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,23 @@ public TsClient(string filePath) : this(new TsClientOptions(filePath)) { }
1212

1313
public void Setup(IApplicationBuilder builder, ILogger? logger, NpgsqlRestOptions options)
1414
{
15+
if (builder is WebApplication app)
16+
{
17+
var factory = app.Services.GetRequiredService<ILoggerFactory>();
18+
if (factory is not null)
19+
{
20+
_logger = factory.CreateLogger(options.LoggerName ?? typeof(TsClient).Namespace ?? "NpgsqlRest.HttpFiles");
21+
}
22+
else
23+
{
24+
_logger = app.Logger;
25+
}
26+
}
27+
else
28+
{
29+
_logger = logger;
30+
}
1531
_builder = builder;
16-
_logger = logger;
1732
_npgsqlRestoptions = options;
1833
}
1934

0 commit comments

Comments
 (0)