Skip to content

Commit ae87fe6

Browse files
committed
[dotnet] Replace lazy caching mechanism in BiDi's constructor with simple initialization
1 parent 9706f56 commit ae87fe6

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

dotnet/src/webdriver/BiDi/BiDi.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using OpenQA.Selenium.BiDi.Communication;
21+
using OpenQA.Selenium.BiDi.Communication.Json;
22+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
2023
using System;
21-
using System.Collections.Concurrent;
2224
using System.Text.Json;
2325
using System.Text.Json.Serialization;
2426
using System.Threading;
2527
using System.Threading.Tasks;
26-
using OpenQA.Selenium.BiDi.Communication;
27-
using OpenQA.Selenium.BiDi.Communication.Json;
28-
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
2928

3029
namespace OpenQA.Selenium.BiDi;
3130

@@ -35,8 +34,6 @@ public sealed class BiDi : IAsyncDisposable
3534
private readonly JsonSerializerOptions _jsonOptions;
3635
private readonly BiDiJsonSerializerContext _jsonContext;
3736

38-
private readonly ConcurrentDictionary<Type, Module> _modules = [];
39-
4037
private BiDi(string url)
4138
{
4239
var uri = new Uri(url);
@@ -68,32 +65,37 @@ private BiDi(string url)
6865
_jsonContext = new BiDiJsonSerializerContext(_jsonOptions);
6966

7067
_broker = new Broker(this, uri, _jsonOptions);
68+
SessionModule = Module.Create<Session.SessionModule>(this, _broker, _jsonOptions, _jsonContext);
69+
BrowsingContext = Module.Create<BrowsingContext.BrowsingContextModule>(this, _broker, _jsonOptions, _jsonContext);
70+
Browser = Module.Create<Browser.BrowserModule>(this, _broker, _jsonOptions, _jsonContext);
71+
Network = Module.Create<Network.NetworkModule>(this, _broker, _jsonOptions, _jsonContext);
72+
InputModule = Module.Create<Input.InputModule>(this, _broker, _jsonOptions, _jsonContext);
73+
Script = Module.Create<Script.ScriptModule>(this, _broker, _jsonOptions, _jsonContext);
74+
Log = Module.Create<Log.LogModule>(this, _broker, _jsonOptions, _jsonContext);
75+
Storage = Module.Create<Storage.StorageModule>(this, _broker, _jsonOptions, _jsonContext);
76+
WebExtension = Module.Create<WebExtension.WebExtensionModule>(this, _broker, _jsonOptions, _jsonContext);
77+
Emulation = Module.Create<Emulation.EmulationModule>(this, _broker, _jsonOptions, _jsonContext);
7178
}
7279

73-
internal Session.SessionModule SessionModule => AsModule<Session.SessionModule>();
74-
75-
public BrowsingContext.BrowsingContextModule BrowsingContext => AsModule<BrowsingContext.BrowsingContextModule>();
80+
internal Session.SessionModule SessionModule { get; }
7681

77-
public Browser.BrowserModule Browser => AsModule<Browser.BrowserModule>();
82+
public BrowsingContext.BrowsingContextModule BrowsingContext { get; }
7883

79-
public Network.NetworkModule Network => AsModule<Network.NetworkModule>();
84+
public Browser.BrowserModule Browser { get; }
8085

81-
internal Input.InputModule InputModule => AsModule<Input.InputModule>();
86+
public Network.NetworkModule Network { get; }
8287

83-
public Script.ScriptModule Script => AsModule<Script.ScriptModule>();
88+
internal Input.InputModule InputModule { get; }
8489

85-
public Log.LogModule Log => AsModule<Log.LogModule>();
90+
public Script.ScriptModule Script { get; }
8691

87-
public Storage.StorageModule Storage => AsModule<Storage.StorageModule>();
92+
public Log.LogModule Log { get; }
8893

89-
public WebExtension.WebExtensionModule WebExtension => AsModule<WebExtension.WebExtensionModule>();
94+
public Storage.StorageModule Storage { get; }
9095

91-
public Emulation.EmulationModule Emulation => AsModule<Emulation.EmulationModule>();
96+
public WebExtension.WebExtensionModule WebExtension { get; }
9297

93-
public TModule AsModule<TModule>() where TModule : Module, new()
94-
{
95-
return (TModule)_modules.GetOrAdd(typeof(TModule), _ => Module.Create<TModule>(this, _broker, _jsonOptions, _jsonContext));
96-
}
98+
public Emulation.EmulationModule Emulation { get; }
9799

98100
public Task<Session.StatusResult> StatusAsync()
99101
{

0 commit comments

Comments
 (0)