You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduce DI support and customizable server options
- Added dependency injection extensions for `Server` registration.
- Introduced `ServerOptions` for configurable server settings (port, hostname, bind address).
- Refactored `Server` constructors to support `ServerOptions`.
- Updated tests to validate DI and `ServerOptions` functionality.
- Simplified namespace declarations with file-scoped syntax.
* Simple web server which can be extended using custom code
27
53
* No dependencies on ASP.NET or other frameworks, self-contained
54
+
* Supports dependency injection and configuration via `IOptions<ServerOptions>`
55
+
* Configurable bind addresses and hostnames for IPv4/IPv6
28
56
29
57
## What it is not
30
58
* This HTTP server is not designed for performance or high capacity
31
59
* It's perfect for small applications, or small need, like to act as _return url_ for OAuth2 authentication using external browser.
32
60
61
+
## Common use cases
62
+
* Return URL for OAuth2 authentication using external browser
63
+
* Remote diagnostics/monitoring on your app
64
+
* Building a headless Windows IoT app (for SSDP discovery or simply end-user configuration)
65
+
* Any other use case where you need to expose a simple web server
66
+
33
67
## Limitations
34
68
* There is no support for HTTP 2.0+ (yet) or WebSockets
35
69
* There is no support for HTTPS (TLS)
36
70
37
-
## What you can do with it
38
-
* Use it for building a headless Windows IoT app (for SSDP discovery or simply end-user configuration)
39
-
* Use it for remote diagnostics/monitoring on your app
71
+
## Configuration and Dependency Injection
72
+
73
+
The server can now be configured via a `ServerOptions` POCO. You can construct `Server` directly with a `ServerOptions` instance, or register it with Microsoft.Extensions.DependencyInjection using `IOptions<ServerOptions>`.
74
+
75
+
### ServerOptions Properties
76
+
77
+
*`Port` - Port number to listen to (0 = dynamic)
78
+
*`BindAddress4` - IPv4 address to bind the listener to (defaults to `IPAddress.Any`)
79
+
*`BindAddress6` - IPv6 address to bind the listener to (defaults to `IPAddress.IPv6Any`)
80
+
*`Hostname4` - Hostname used to compose the public IPv4 URI (defaults to "127.0.0.1")
81
+
*`Hostname6` - Hostname used to compose the public IPv6 URI (defaults to "::1")
82
+
83
+
### Dynamic Port Assignment (Recommended)
84
+
85
+
Using port `0` enables **dynamic port assignment**, which is the **recommended approach** for most applications:
86
+
87
+
**Key Advantages:**
88
+
-**Zero port conflicts**: The operating system automatically assigns an available port
89
+
-**Perfect for testing**: Multiple test instances can run simultaneously without conflicts
90
+
-**Microservices architecture**: Each service gets its own unique port automatically
91
+
-**Team collaboration**: No need to coordinate port assignments between developers
92
+
-**CI/CD friendly**: Parallel builds and tests work seamlessly
93
+
94
+
**Best Practices with Dynamic Ports:**
95
+
96
+
```csharp
97
+
// ✅ Recommended: Use dynamic ports (default behavior)
This allows you to control the bind addresses and hostnames used to compose the public URIs that the server logs, which is especially useful for OAuth callbacks and REST API applications.
182
+
183
+
## Tips
184
+
185
+
### Opening port on Windows 10 IoT (typically on a Raspberry Pi)
44
186
If you want to open "any" port on a Raspberry Pi running Windows 10 IoT, you may
0 commit comments