Skip to content

Commit 670a71f

Browse files
committed
Ensure the bootstrapper is initialized
1 parent a187eb3 commit 670a71f

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

HttpWebClient/HttpWebClientBootstrap.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//The MIT License(MIT)
1+
// The MIT License(MIT)
22
//
3-
//Copyright(c) 2015-2017 Ripcord Software Ltd
3+
// Copyright(c) 2015-2017 Ripcord Software Ltd
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,7 @@
2121
// SOFTWARE.
2222

2323
using System;
24+
using System.Threading;
2425

2526
namespace RipcordSoftware.HttpWebClient
2627
{
@@ -29,9 +30,22 @@ namespace RipcordSoftware.HttpWebClient
2930
/// </summary>
3031
internal static class HttpWebClientBootstrap
3132
{
32-
static HttpWebClientBootstrap()
33+
private static volatile bool _initialized = false;
34+
private static object _lock = new object();
35+
36+
internal static void Initialize()
3337
{
34-
HttpWebClientContainer.Register<IHttpWebClientSocket>((h, p, t) => { return HttpWebClientSocket.GetSocket((string)h, (int)p, (int)t); });
38+
if (!_initialized)
39+
{
40+
lock (_lock)
41+
{
42+
if (!_initialized)
43+
{
44+
HttpWebClientContainer.Register<IHttpWebClientSocket>((h, p, t) => { return HttpWebClientSocket.GetSocket((string)h, (int)p, (int)t); });
45+
_initialized = true;
46+
}
47+
}
48+
}
3549
}
3650
}
3751
}

HttpWebClient/HttpWebClientRequest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//The MIT License(MIT)
1+
// The MIT License(MIT)
22
//
3-
//Copyright(c) 2015-2017 Ripcord Software Ltd
3+
// Copyright(c) 2015-2017 Ripcord Software Ltd
44
//
55
// Permission is hereby granted, free of charge, to any person obtaining a copy
66
// of this software and associated documentation files (the "Software"), to deal
@@ -41,6 +41,11 @@ public class HttpWebClientRequest
4141
#endregion
4242

4343
#region Constructor
44+
static HttpWebClientRequest()
45+
{
46+
HttpWebClientBootstrap.Initialize();
47+
}
48+
4449
private HttpWebClientRequest()
4550
{
4651
Method = "GET";

0 commit comments

Comments
 (0)