Skip to content

Commit 4953592

Browse files
Inject IOptions<T>
1 parent 0599c9c commit 4953592

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/Sentry.Maui/Internal/MauiSessionReplayMaskControlsOfTypeBinder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ internal class MauiSessionReplayMaskControlsOfTypeBinder : IMauiElementEventBind
1515

1616
internal bool IsEnabled { get; }
1717

18-
public MauiSessionReplayMaskControlsOfTypeBinder(SentryMauiOptions options)
18+
public MauiSessionReplayMaskControlsOfTypeBinder(IOptions<SentryMauiOptions> options)
1919
{
20-
_options = options;
20+
_options = options.Value;
2121
#if __ANDROID__
22-
var replayOptions = options.Native.ExperimentalOptions.SessionReplay;
22+
var replayOptions = _options.Native.ExperimentalOptions.SessionReplay;
2323
IsEnabled = replayOptions is { IsSessionReplayEnabled: true, IsTypeMaskingUsed: true };
2424
#else
2525
IsEnabled = false;

test/Sentry.Maui.Tests/MauiCustomSessionReplayMaskBinderTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public Fixture()
2020
var logger = Substitute.For<IDiagnosticLogger>();
2121
logger.IsEnabled(Arg.Any<SentryLevel>()).Returns(true);
2222
Options.DiagnosticLogger = logger;
23-
ControlsOfTypeBinder = new MauiSessionReplayMaskControlsOfTypeBinder(Options);
23+
var options = Microsoft.Extensions.Options.Options.Create(Options);
24+
ControlsOfTypeBinder = new MauiSessionReplayMaskControlsOfTypeBinder(options);
2425
}
2526
}
2627

@@ -72,7 +73,8 @@ public void SessionReplayEnabled_IsEnabled(
7273
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = onErrorSampleRate;
7374

7475
// Act
75-
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(options);
76+
var iOptions = Microsoft.Extensions.Options.Options.Create(options);
77+
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions);
7678

7779
// Assert
7880
binder.IsEnabled.Should().Be(true);
@@ -88,7 +90,8 @@ public void SessionReplayDisabled_IsNotEnabled()
8890
// No sessionSampleRate or onErrorSampleRate set... so should be disabled
8991

9092
// Act
91-
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(options);
93+
var iOptions = Microsoft.Extensions.Options.Options.Create(options);
94+
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions);
9295

9396
// Assert
9497
binder.IsEnabled.Should().Be(false);
@@ -105,7 +108,8 @@ public void UseSentry_NoMaskedControls_DoesNotRegisterMauiVisualElementEventsBin
105108
options.Native.ExperimentalOptions.SessionReplay.MaskedControls.Clear();
106109

107110
// Act
108-
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(options);
111+
var iOptions = Microsoft.Extensions.Options.Options.Create(options);
112+
var binder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions);
109113

110114
// Assert
111115
binder.IsEnabled.Should().Be(false);

test/Sentry.Maui.Tests/MauiEventsBinderTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ public void ElementEventBinders_EnabledOnly()
4646
options1.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0;
4747
options1.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0;
4848
#endif
49-
var enabledBinder = new MauiSessionReplayMaskControlsOfTypeBinder(options1);
49+
var iOptions1 = Microsoft.Extensions.Options.Options.Create(options1);
50+
var enabledBinder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions1);
5051

5152
var options2 = new SentryMauiOptions { Dsn = ValidDsn };
5253
#if __ANDROID__
5354
options2.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 0.0;
5455
options2.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 0.0;
5556
#endif
56-
var disabledBinder = new MauiSessionReplayMaskControlsOfTypeBinder(options2);
57+
var iOptions2 = Microsoft.Extensions.Options.Options.Create(options2);
58+
var disabledBinder = new MauiSessionReplayMaskControlsOfTypeBinder(iOptions2);
5759

5860
var buttonEventBinder = new MauiButtonEventsBinder();
5961

0 commit comments

Comments
 (0)