Skip to content

Commit 8ce5dad

Browse files
committed
Add sample about keyed services
1 parent b3afb1b commit 8ce5dad

File tree

12 files changed

+129
-3
lines changed

12 files changed

+129
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Samples for ASP.NET Core 6.0, 7.0 and 8.0 RC 2 (503)
1+
# Samples for ASP.NET Core 6.0, 7.0 and 8.0 RC 2 (504)
22

3-
- Samples for ASP.NET Core **8.0 RC 2** is available [here](/projects/.net8) (40).
3+
- Samples for ASP.NET Core **8.0 RC 2** is available [here](/projects/.net8) (41).
44
- Samples for ASP.NET Core **7.0** is available [here](/projects/.net7) (45).
55
- Samples for ASP.NET Core **8.0 Preview 6** using EdgeDB.NET is [here](https://github.com/edgedb/edgedb-net).
66

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"dotnet.defaultSolution": "ComponentTwentySix.sln"
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Router AppAssembly="typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<h1>Page not found</h1>
7+
<p>Sorry, but there's nothing here!</p>
8+
</NotFound>
9+
</Router>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<ImplicitUsings>true</ImplicitUsings>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.2.*" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-rc.2.*" />
9+
<Watch Include="**\*.cshtml" />
10+
<Watch Include="**\*.razor" />
11+
</ItemGroup>
12+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComponentTwentySeven", "ComponentTwentySeven.csproj", "{23E5009B-0E29-4D9F-8BB7-2D7183A97DCA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{23E5009B-0E29-4D9F-8BB7-2D7183A97DCA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{23E5009B-0E29-4D9F-8BB7-2D7183A97DCA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{23E5009B-0E29-4D9F-8BB7-2D7183A97DCA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{23E5009B-0E29-4D9F-8BB7-2D7183A97DCA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {A0B52EB0-A57C-4AF0-9C40-C74BB7385C44}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/"
2+
3+
@Msg1.Message <br/>
4+
@Msg2.Message
5+
6+
@code
7+
{
8+
[Inject(Key = "msg1")]
9+
public IMessage Msg1 { get; set; }
10+
11+
12+
[Inject(Key = "msg2")]
13+
public IMessage Msg2 { get; set; }
14+
}
15+
16+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
2+
using ComponentTwentySeven;
3+
4+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
5+
builder.RootComponents.Add<App>("app");
6+
builder.Services.AddKeyedSingleton<IMessage>("msg1", (_, _) => new Msg("Hello world"));
7+
builder.Services.AddKeyedSingleton<IMessage>("msg2", (_, _) => new Msg("Goodbyeworld"));
8+
9+
var app = builder.Build();
10+
await app.RunAsync();
11+
12+
13+
public interface IMessage
14+
{
15+
string Message { get; }
16+
}
17+
18+
19+
public class Msg(string message) : IMessage
20+
{
21+
public string Message => message;
22+
}
23+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inject keyed services into components
2+
3+
This sample shows how to use `[Inject(Key)]` in consuming keyed services.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="main">
4+
<div class="content px-4">
5+
@Body
6+
</div>
7+
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@using Microsoft.AspNetCore.Components.Web
2+
@using Microsoft.AspNetCore.Components.Routing
3+
@using Microsoft.JSInterop
4+
@using ComponentTwentySeven
5+
@using ComponentTwentySeven.Shared

0 commit comments

Comments
 (0)