mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Simplify docs around receiving an INodeServices instance from DI
This commit is contained in:
@@ -63,30 +63,12 @@ public void ConfigureServices(IServiceCollection services)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can receive an instance of `NodeServices` as a constructor parameter to any MVC controller, e.g.:
|
Now you can receive an instance of `NodeServices` as an action method parameter to any MVC action, and then use it to make calls into Node.js code, e.g.:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
using Microsoft.AspNetCore.NodeServices;
|
public async Task<IActionResult> MyAction([FromServices] INodeServices nodeServices)
|
||||||
|
|
||||||
public class SomeController : Controller
|
|
||||||
{
|
{
|
||||||
private INodeServices _nodeServices;
|
var result = await nodeServices.InvokeAsync<int>("./addNumbers", 1, 2);
|
||||||
|
|
||||||
public SomeController(INodeServices nodeServices)
|
|
||||||
{
|
|
||||||
_nodeServices = nodeServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ... your action methods are here ...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Then you can use this instance to make calls into Node.js code, e.g.:
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
public async Task<IActionResult> MyAction()
|
|
||||||
{
|
|
||||||
var result = await _nodeServices.InvokeAsync<int>("./addNumbers", 1, 2);
|
|
||||||
return Content("1 + 2 = " + result);
|
return Content("1 + 2 = " + result);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user