Skip to content

Commit

Permalink
Merge to Live (#30400)
Browse files Browse the repository at this point in the history
* Update target-aspnetcore.md (#30388)

* Add documentation about hosting gRPC in non-ASP.NET Core projects (#30390)

Co-authored-by: Rick Anderson <[email protected]>

---------

Co-authored-by: James Newton-King <[email protected]>
Co-authored-by: Rick Anderson <[email protected]>
  • Loading branch information
3 people authored Sep 19, 2023
1 parent b269f25 commit 00387ca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion aspnetcore/fundamentals/target-aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ For example, to add the web API client:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
23 changes: 22 additions & 1 deletion aspnetcore/grpc/aspnetcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ For more information on enabling HTTP/2 and TLS with Kestrel, see [Kestrel endpo
:::moniker-end

## Host gRPC in non-ASP.NET Core projects

An ASP.NET Core gRPC server is typically created from the gRPC template. The project file created by the template uses `Microsoft.NET.SDK.Web` as the SDK:

[!code-xml[](~/grpc/aspnetcore/Server-web.csproj?highlight=1)]

The `Microsoft.NET.SDK.Web` SDK value automatically adds a reference to the ASP.NET Core framework. The reference allows the app to use ASP.NET Core types required to host a server.

You can add a gRPC server to non-ASP.NET Core projects with the following project file settings:

[!code-xml[](~/grpc/aspnetcore/Server.csproj?highlight=1,7)]

The preceding project file:

* Adds a framework reference to `Microsoft.AspNetCore.App`.
* The framework reference allows non-ASP.NET Core apps, such as Windows Services, WPF apps, or WinForms apps to use ASP.NET Core APIs.
* The app can now use ASP.NET Core APIs to start an ASP.NET Core server.
* Adds gRPC requirements:
* NuGet package reference to [`Grpc.AspNetCore`](https://www.nuget.org/packages/Grpc.AspNetCore).
* `.proto` file.

For more information about using the `Microsoft.AspNetCore.App` framework reference, see [Use the ASP.NET Core shared framework](xref:fundamentals/target-aspnetcore#use-the-aspnet-core-shared-framework).
## Integration with ASP.NET Core APIs

gRPC services have full access to the ASP.NET Core features such as [Dependency Injection](xref:fundamentals/dependency-injection) (DI) and [Logging](xref:fundamentals/logging/index). For example, the service implementation can resolve a logger service from the DI container via the constructor:
Expand All @@ -271,7 +293,6 @@ The gRPC API provides access to some HTTP/2 message data, such as the method, ho

[!code-csharp[](~/grpc/aspnetcore/sample/GrcpService/GreeterService2.cs?highlight=6-7&name=snippet)]


## Additional resources

* <xref:tutorials/grpc/grpc-start>
Expand Down
8 changes: 8 additions & 0 deletions aspnetcore/grpc/aspnetcore/Server-web.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.47.0" />
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions aspnetcore/grpc/aspnetcore/Server.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.47.0" />
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />

<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

</Project>
11 changes: 1 addition & 10 deletions aspnetcore/grpc/interprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ An ASP.NET Core gRPC server is usually created from the gRPC template. The proje

The `Microsoft.NET.SDK.Web` SDK value automatically adds a reference to the ASP.NET Core framework. The reference allows the app to use ASP.NET Core types required to host a server.

It's also possible to add a server to existing non-ASP.NET Core projects. Add the `Microsoft.AspNetCore.App` framework to the project file:

[!code-xml[](~/grpc/interprocess/Server.csproj?highlight=4)]

The preceding project file:

* Adds a framework reference to `Microsoft.AspNetCore.App`. The framework reference allows non-ASP.NET Core apps, such as Windows Services, WPF apps, or WinForms apps to use ASP.NET Core APIs. The app can now use ASP.NET Core APIs to start an ASP.NET Core server.
* Adds gRPC requirements:
* NuGet package reference to [`Grpc.AspNetCore`](https://www.nuget.org/packages/Grpc.AspNetCore).
* `.proto` file.
It's also possible to add a server to existing non-ASP.NET Core projects, such as Windows Services, WPF apps, or WinForms apps. See [Host gRPC in non-ASP.NET Core projects](xref:grpc/aspnetcore#host-grpc-in-non-aspnet-core-projects) for more information.

## Inter-process communication (IPC) transports

Expand Down

0 comments on commit 00387ca

Please sign in to comment.