Nancy 2.0.0-clinteastwood feedback

Created on 22 Dec 2016  ·  8Comments  ·  Source: NancyFx/Nancy

If you find any problems, please open an issue and provide as much information, as possible, to help us identify your problem. Alternatively, feel free to submit a pull-request if you think you can help resolve the problem. If you need a guiding hand, on how to get started with pull-requests, please have a look at our contributing guidelines. Make sure you don't miss the style guidelines, I won't :D

NOTE: Because Nancy 2.0-clinteastwood is a pre-release, you are going to have to install packages using the -pre toggle, i.e install-package Nancy -pre

Please use this issue for posting comments that are not directly related to any specific reported bug or pull-request.

TODO

The following is a list of identified task that needs to be performed in the wake of the 2.0.0-clinteastwood release and should be completed before 2.0.0-dangermouse is released. Edit the TODO-list and add items as they are found, add links to pull-requests that are sent to close them

  • [x] Make sure AsyncUsageAnalyzers it set to a build dependency in all project.json and packages.config Correct example to mirror here - (pull request #2700 @jchannon
  • [x] Remove all old *.nuspec files in all projects (including Nancy) (pull-request #2658 @jchannon)
  • [x] Update Nancy.Hosting.Aspnet\project.json to include web.config.transform in the package (pull-request #2661 @thecodejunkie)
  • [x] Update Nancy.ViewEngines.Razor\project.json to include app/web.config.transform in the package (pull-request #2661 @thecodejunkie)
  • [ ] Update Nancy.ViewEngines.Razor\project.json to include Nancy.ViewEngines.Razor.BuildProvider (including build targets) in the package

Planned changes

  • [ ] Remove one of Request.Cookies and Request.Headers.Cookie see #2628 for discussions
  • [ ] Improve the Before and After hook syntax and capabilities #2665
  • [ ] Look into "Potential Performance Problem with Nancy.Routing.Route.Invoke #2623"
  • [ ] Add configuration support for content negotiation. See #2671 for discussion on automatic extension resolution
  • [ ] Update testing infrastructure to support netstandard, see issue #2612 and pull-request #2628
  • [ ] Convert remaining sub-systems to async, see pull-request #2577
  • [ ] Remove the last remaining parts of StaticConfiguration

Known limitations

  • Some packages may install AsyncUsageAnalyzers as a dependency. This should be safe to be removed and will not be included in 2.0.0-dangermouse as it will be marked as a build dependency in all projects
  • The Nancy.Hosting.Aspnet package will not apply *.config transformations`, to wire up the hosting, you will have to apply it yourself
  • The Nancy.ViewEngines.Razor package will not apply *.config transformations` to wire up the view engines configuration options, you will have to apply it yourself
  • The build providers for Nancy.ViewEngines.Razor are missing from the NuGet package, causing problems with syntax highlighting in Nancy Razor views
Improvement Epic

Most helpful comment

It's because the base module doesn't have a constructor that the IoC container can satisfy. It doesn't know how to handle string. If the BaseModule Isn't supposed to be called by itself, I suggest you make it abstract...

All 8 comments

This compiles, but throws a run-time NullReferenceException:

pipelines.BeforeRequest.AddItemToStartOfPipeline((ctx, _) =>
{
    // do stuff
    // Func<NancyContext, Response>, Func<NancyContext, CancellationToken, Response>
    return null;
});

This works:

pipelines.BeforeRequest.AddItemToStartOfPipeline((ctx, _) =>
{
    //do stuff
    // Func<NancyContext, CancellationToken, Task<Response>>
    return Task<Response>.FromResult((Response)null);
});

It took a bit of bashing my head against the wall until I figured it out which is neither super-duper nor happy.

@danbarua thanks. I've opened https://github.com/NancyFx/Nancy/issues/2665 because I want to give the pipeline stuff an overhaul as soon as we've had the time to look at the bootstrapper (which will happen as soon as I've moved us to the new csproj format and that's happening now in #2720)

YAK SHAVING! 😄

This code throw an exception, is this bug?

```C#

public class BaseModule : NancyModule
{
public BaseModule(string url) : base(url)
{
//Custom logic
}
}

public class A : BaseModule
{
public A() : base("urlA")
{

}

}

public class B : NancyModule
{
public B()
{

}

}


System.InvalidOperationException occurred
HResult=0x80131509
Message=Something went wrong when trying to satisfy one of the dependencies during composition, make sure that you've registered all new dependencies in the container and inspect the innerexception for more details.
Source=
StackTrace:
at Nancy.Bootstrapper.NancyBootstrapperBase1.SafeGetNancyEngineInstance() at Nancy.Bootstrapper.NancyBootstrapperBase1.GetEngine()
at Nancy.Owin.NancyMiddleware.UseNancy(NancyOptions options)
at Nancy.Owin.DelegateExtensions.UseNancy(Action1 builder, NancyOptions options) at PiggyBank.Site.Startup.<>c.<Configure>b__2_0(Action1 x) in E:visual_studiopiggy-banksourcePiggyBank.SiteStartup.cs:line 31
at Microsoft.AspNetCore.Builder.OwinExtensions.UseOwin(IApplicationBuilder builder, Action`1 pipeline)
at PiggyBank.Site.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in E:visual_studiopiggy-banksourcePiggyBank.SiteStartup.cs:line 31

Inner Exception 1:
TinyIoCResolutionException: Unable to resolve type: Nancy.NancyEngine

Inner Exception 2:
TinyIoCResolutionException: Unable to resolve type: Nancy.Routing.DefaultRequestDispatcher

Inner Exception 3:
TinyIoCResolutionException: Unable to resolve type: Nancy.Routing.DefaultRouteResolver

Inner Exception 4:
TinyIoCResolutionException: Unable to resolve type: Nancy.Routing.RouteCache

Inner Exception 5:
TinyIoCResolutionException: Unable to resolve type: BaseModule

Inner Exception 6:
TinyIoCResolutionException: Unable to resolve type: System.String

Inner Exception 7:
TinyIoCResolutionException: Unable to resolve type: System.Char[]

Inner Exception 8:
ArgumentNullException: Value cannot be null.

```

It's because the base module doesn't have a constructor that the IoC container can satisfy. It doesn't know how to handle string. If the BaseModule Isn't supposed to be called by itself, I suggest you make it abstract...

Old:

Get["post/{id}"] = Get["old/post/{id}"] = p =>{};

New(2.0):

?

Get("post/{id}", MyMethod);
Get("old/post/{id}", MyMethod);

Get("post/{id}", MyMethod);
Get("old/post/{id}", MyMethod);

That usage adds some indirection. I personally don't like that. Not a problem though.

Maybe it is possible to have some method overloads for fluent expression? example:

Get("post/{id}")
.Get("old/post/{id}")
.Post("whatever/{id}", p => { return HttpStatusCode.Ok });

An alternate expression

Get("post/{id}")
.Get("old/post/{id}")
.Post("whatever/{id}")
.Do(p => { return HttpStatusCode.Ok });

I can take a stab at PR if this is desirable

Was this page helpful?
0 / 5 - 0 ratings