Route without lambda expression

Below is an official example for registering routes in Nancy . But what if I don't want to "do something" in this method, but instead do it in DoSomething()?

public class ProductsModule : NancyModule
{
    public ProductsModule()
    {
        Get["/products/{id}"] = _ =>
        {
            //do something
        };
    }
}

public abstract class NancyModule : INancyModule, IHideObjectMembers
{
    public RouteBuilder Get { get; }
}

public class RouteBuilder : IHideObjectMembers
{
    public RouteBuilder(string method, NancyModule parentModule);
    public Func<dynamic, dynamic> this[string path] { set; }
}

I do not know what signature DoSomethingshould have. Could this work something like below? It's not that I should not use a lambda expression; I'm just curious, because all of these Nancy models use a look rather strange and unique.

public class ProductsModule : NancyModule
{
    ???? DoSomething(????)
    {
        //do something
        return ????
    }

    public ProductsModule()
    {
        Get["/products/{id}"] = DoSomething;
    }
}
+4
source share
1 answer

From the Nancy documentation:

- , , . , - Func<dynamic, dynamic>, DynamicDictionary, , Nancy DynamicDictionary.

, :

Get["/products/{id}"] = DoSomething;

DoSomething :

private dynamic DoSomething(dynamic parameters)
+3

Source: https://habr.com/ru/post/1665971/


All Articles