File tree 2 files changed +5
-8
lines changed
2 files changed +5
-8
lines changed Original file line number Diff line number Diff line change @@ -98,10 +98,9 @@ An instance of `Clipboard` can be injected into `IServiceCollection`:
98
98
<!-- snippet: InjectClipboard -->
99
99
<a id =' snippet-injectclipboard ' ></a >
100
100
``` cs
101
- serviceCollection .AddSingleton <IClipboard >(
102
- _ => new BlazorClipboard (_ .GetRequiredService <IJSRuntime >()));
101
+ serviceCollection .InjectClipboard ();
103
102
```
104
- <sup ><a href =' /src/BlazorSample/Program.cs#L11-L14 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-injectclipboard ' title =' Start of snippet ' >anchor</a ></sup >
103
+ <sup ><a href =' /src/BlazorSample/Program.cs#L9-L11 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-injectclipboard ' title =' Start of snippet ' >anchor</a ></sup >
105
104
<!-- endSnippet -->
106
105
107
106
The instance should be injected by using ` IClipboard ` .
@@ -134,11 +133,10 @@ Instead inject an `IClipboard`:
134
133
``` cs
135
134
var builder = WebAssemblyHostBuilder .CreateDefault ();
136
135
var serviceCollection = builder .Services ;
137
- serviceCollection .AddSingleton <IClipboard >(
138
- _ => new BlazorClipboard (_ .GetRequiredService <IJSRuntime >()));
136
+ serviceCollection .InjectClipboard ();
139
137
builder .RootComponents .Add <App >(" app" );
140
138
```
141
- <sup ><a href =' /src/BlazorSample/Program.cs#L8-L16 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-blazorstartup ' title =' Start of snippet ' >anchor</a ></sup >
139
+ <sup ><a href =' /src/BlazorSample/Program.cs#L6-L13 ' title =' Snippet source file ' >snippet source</a > | <a href =' #snippet-blazorstartup ' title =' Start of snippet ' >anchor</a ></sup >
142
140
<!-- endSnippet -->
143
141
144
142
Then consume it:
Original file line number Diff line number Diff line change 9
9
var builder = WebAssemblyHostBuilder . CreateDefault ( ) ;
10
10
var serviceCollection = builder . Services ;
11
11
#region InjectClipboard
12
- serviceCollection . AddSingleton < IClipboard > (
13
- _ => new BlazorClipboard ( _ . GetRequiredService < IJSRuntime > ( ) ) ) ;
12
+ serviceCollection . AddSingleton < IClipboard > ( _ => new BlazorClipboard ( _ . GetRequiredService < IJSRuntime > ( ) ) ) ;
14
13
#endregion
15
14
builder . RootComponents . Add < App > ( "app" ) ;
16
15
#endregion
You can’t perform that action at this time.
0 commit comments