Skip to content

Commit aae225b

Browse files
author
Adrian Hall
committed
(#48) Update sample for .NET9 and OpenApi support
1 parent 408eefa commit aae225b

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

samples/datasync-server/src/Sample.Datasync.Server/Program.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@
1616
string? swaggerDriver = builder.Configuration["Swagger:Driver"];
1717
bool nswagEnabled = swaggerDriver?.Equals("NSwag", StringComparison.InvariantCultureIgnoreCase) == true;
1818
bool swashbuckleEnabled = swaggerDriver?.Equals("Swashbuckle", StringComparison.InvariantCultureIgnoreCase) == true;
19+
bool openApiEnabled = swaggerDriver?.Equals("NET9", StringComparison.InvariantCultureIgnoreCase) == true;
1920

2021
builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(connectionString));
2122
builder.Services.AddDatasyncServices();
2223
builder.Services.AddControllers();
2324

2425
if (nswagEnabled)
2526
{
26-
_ = builder.Services
27-
.AddOpenApiDocument(options => options.AddDatasyncProcessor());
27+
_ = builder.Services.AddOpenApiDocument(options => options.AddDatasyncProcessor());
2828
}
2929

3030
if (swashbuckleEnabled)
3131
{
32-
_ = builder.Services
33-
.AddEndpointsApiExplorer()
34-
.AddSwaggerGen(options => options.AddDatasyncControllers());
32+
_ = builder.Services.AddEndpointsApiExplorer();
33+
_ = builder.Services.AddSwaggerGen(options => options.AddDatasyncControllers());
34+
}
35+
36+
if (openApiEnabled)
37+
{
38+
_ = builder.Services.AddOpenApi();
3539
}
3640

3741
WebApplication app = builder.Build();
@@ -58,4 +62,9 @@
5862
app.UseAuthorization();
5963
app.MapControllers();
6064

65+
if (openApiEnabled)
66+
{
67+
_ = app.MapOpenApi(pattern: "swagger/{documentName}/swagger.json");
68+
}
69+
6170
app.Run();

samples/datasync-server/src/Sample.Datasync.Server/Properties/launchSettings.json

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
{
22
"$schema": "http://json.schemastore.org/launchsettings.json",
3-
"iisSettings": {
4-
"windowsAuthentication": false,
5-
"anonymousAuthentication": true,
6-
"iisExpress": {
7-
"applicationUrl": "http://localhost:48768",
8-
"sslPort": 44300
9-
}
10-
},
113
"profiles": {
124
"https": {
135
"commandName": "Project",
146
"dotnetRunMessages": true,
157
"launchBrowser": true,
16-
"launchUrl": "https://localhost:5001/tables/todoitem",
17-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
18-
"environmentVariables": {
19-
"ASPNETCORE_ENVIRONMENT": "Development"
20-
},
21-
"sqlDebugging": true
22-
},
23-
"IIS Express": {
24-
"commandName": "IISExpress",
25-
"launchBrowser": true,
26-
"launchUrl": "https://localhost:44300/tables/todoitem",
8+
"launchUrl": "tables/todoitem",
9+
"applicationUrl": "https://localhost:5001",
2710
"environmentVariables": {
2811
"ASPNETCORE_ENVIRONMENT": "Development"
2912
},
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<UserSecretsId>2fc55b72-4090-46ad-ae44-8b6a415339b8</UserSecretsId>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="CommunityToolkit.Datasync.Server" Version="8.0.4" />
11-
<PackageReference Include="CommunityToolkit.Datasync.Server.EntityFrameworkCore" Version="8.0.4" />
12-
<PackageReference Include="CommunityToolkit.Datasync.Server.NSwag" Version="8.0.4" />
13-
<PackageReference Include="CommunityToolkit.Datasync.Server.Swashbuckle" Version="8.0.4"/>
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.11">
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.1">
1613
<PrivateAssets>all</PrivateAssets>
1714
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1815
</PackageReference>
1916
</ItemGroup>
2017

18+
<ItemGroup>
19+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.Abstractions\CommunityToolkit.Datasync.Server.Abstractions.csproj" />
20+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.EntityFrameworkCore\CommunityToolkit.Datasync.Server.EntityFrameworkCore.csproj" />
21+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.NSwag\CommunityToolkit.Datasync.Server.NSwag.csproj" />
22+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.Swashbuckle\CommunityToolkit.Datasync.Server.Swashbuckle.csproj" />
23+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server\CommunityToolkit.Datasync.Server.csproj" />
24+
</ItemGroup>
25+
2126
</Project>

samples/datasync-server/src/Sample.Datasync.Server/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"Microsoft.AspNetCore": "Warning"
99
}
1010
},
11-
"AllowedHosts": "*"
11+
"AllowedHosts": "*",
12+
"Swagger": {
13+
"Driver": "net9"
14+
}
1215
}

0 commit comments

Comments
 (0)