1
+ using Newtonsoft . Json ;
1
2
using System . Data ;
2
3
using System . Net ;
3
4
using System . Reflection ;
4
5
using System . Text ;
5
- using System . Text . Json . Serialization ;
6
- using Newtonsoft . Json ;
6
+ using System . Text . Json ;
7
7
using Tigernet . Hosting . Attributes . HttpMethods ;
8
8
using Tigernet . Hosting . Attributes . Resters ;
9
9
using Tigernet . Hosting . Exceptions ;
10
- using JsonConverter = System . Text . Json . Serialization . JsonConverter ;
11
- using JsonSerializer = System . Text . Json . JsonSerializer ;
12
10
13
- namespace Tigernet . Hosting ;
11
+ namespace Tigernet . Hosting ;
14
12
15
13
#pragma warning disable
16
14
/// <summary>
@@ -47,10 +45,10 @@ public partial class TigernetHostBuilder
47
45
/// Constructor for TigernetHostBuilder class. It takes in a string prefix and sets it as the prefix for the HttpListener.
48
46
/// </summary>
49
47
/// <param name="prefix">The prefix for the HttpListener</param>
50
- public TigernetHostBuilder ( string prefix )
48
+ public TigernetHostBuilder ( )
51
49
{
52
- _prefix = prefix ;
53
- _listener . Prefixes . Add ( prefix ) ;
50
+ _prefix = GetPrefix ( ) ;
51
+ _listener . Prefixes . Add ( _prefix ) ;
54
52
_services = new Dictionary < Type , Type > ( ) ;
55
53
}
56
54
@@ -183,7 +181,7 @@ public void MapResters()
183
181
}
184
182
}
185
183
}
186
-
184
+
187
185
/// <summary>
188
186
/// Retrieves a validated HttpMethodAttribute from an array of HttpMethodAttributes.
189
187
/// </summary>
@@ -302,4 +300,25 @@ private async ValueTask<object[]> GetArguments(MethodInfo method, HttpListenerCo
302
300
303
301
return result ;
304
302
}
303
+
304
+ private string GetPrefix ( )
305
+ {
306
+ // get the assembly that is using this library
307
+ var assembly = Assembly . GetCallingAssembly ( ) ;
308
+
309
+ // Set the path of the file within the project
310
+ string filePath = @"../../../Properties/launchSettings.json" ;
311
+
312
+ // Read the contents of the file
313
+ string launchSettingsJson = File . ReadAllText ( filePath ) ;
314
+
315
+ // Parse the JSON string into a JsonDocument object
316
+ JsonDocument launchSettingsDoc = JsonDocument . Parse ( launchSettingsJson ) ;
317
+
318
+ // Navigate the JSON object to get the desired value
319
+ JsonElement applicationUrlElement = launchSettingsDoc . RootElement
320
+ . GetProperty ( "applicationUrl" ) ;
321
+
322
+ return applicationUrlElement . GetString ( ) ;
323
+ }
305
324
}
0 commit comments