Created
June 19, 2014 11:25
-
-
Save bronumski/cd8eda47279b1009e488 to your computer and use it in GitHub Desktop.
Creates or gets a uri for a service or unique name with a random free port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static class UriManager | |
| { | |
| private static readonly IDictionary<string, Uri> Uris = new Dictionary<string, Uri>(); | |
| public static Uri GetUriForService<TService>() | |
| { | |
| return GetUri(typeof (TService).Name); | |
| } | |
| public static Uri GetUri(string serviceName) | |
| { | |
| if (Uris.ContainsKey(serviceName)) | |
| { | |
| return Uris[serviceName]; | |
| } | |
| var uri = new UriBuilder(Uri.UriSchemeHttp, IPAddress.Loopback.ToString(), TcpPort.NextFreePort()).Uri; | |
| Uris.Add(serviceName, uri); | |
| return uri; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment