Open andersonom opened 5 years ago
+1
I just tested Nancy (pre1911) with Core 2.1 and it works just fine. I changed a few things compared to the code you posted:
GetMyModel
is async, so it should be called in an async manner, something like:Get("/Home/{param}", async (args, ct) =>
{
var result = await myService.GetMyModel((string) args.param, ct);
return Response.AsJson(result);
});
In your code, the Task
object is serialized to JSON, which is not what we want.
Also, I just did this to have the service managed entirely by TinyIoC:
container.Register<IMyService, MyService>();
Of course, if your service is external to Nancy it makes sense to inject it into the bootstrapper, otherwise the above is fine.
It actually work in a Core 2.2 project. Just converted the project I've been working on from 2.0 to 2.2 and Nancy didn't have any issues. As a bonus, I'm noticing significantly lower CPU load after moving to 2.2 on a simple load test.
That said, it would be nice to officially get things updated (net 472, core 2.2 and all packages). I just ran through it and some updated packages have breaking changes.
Prerequisites
DEBUG
andRELEASE
modeDescription
Nancy is not working for dotnet core 2.1, only for 2.0.
Steps to Reproduce
Created a project pointing dotnet core 2.1 web empty project
Created MyService calling a external API using Flurl.Http package: `public class MyService : IMyService { private readonly IAppConfiguration _appConfig;
public MyService(IAppConfiguration appConfig) { _appConfig = appConfig; }
public async Task GetMyModel(string param)
{
return await "httpUrl"
.AllowAnyHttpStatus()
.AppendPathSegment("parameter")
.GetJsonAsync();
}
}`
Create a injection of a my new class MyService inside my custom Bootstrapper: `public class MyDistanceBootstrapper : DefaultNancyBootstrapper { private readonly IAppConfiguration _appConfig; private readonly IMytService _myService;
}`
When backing to the NancyModule route it throw an exception: `public class MyModule : NancyModule { public MyModule(IAppConfiguration appConfig, IMyService myService) { Get("/Home/param", args => Response.AsJson(myService.GetMyModel((string)args.param)));
}`
Exception Process is terminating due to StackOverflowException.
System.StackOverflowException HResult=0x800703E9 Source=
StackTrace: