Unten ist the official example für die Registrierung von Routen in Nancy. Aber was, wenn ich in dieser Methode nicht "etwas tun will", sondern stattdessen in DoSomething()
?Route ohne Lambda-Ausdruck
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; }
}
Ich weiß nicht, welche Unterschrift DoSomething
haben sollte. Kann das so etwas wie unten funktionieren? Es ist nicht so, dass ich nicht den Lambda-Ausdruck benutzen darf; Ich bin nur neugierig, weil all diese Muster, die Nancy benutzt, ziemlich bizarr und einzigartig aussehen.
public class ProductsModule : NancyModule
{
???? DoSomething(????)
{
//do something
return ????
}
public ProductsModule()
{
Get["/products/{id}"] = DoSomething;
}
}
Sie können Sie die Methode innerhalb der Lambda nennen? –
Ja, das war der erste Workaround, den ich mir ausgedacht habe. Aber ist es möglich, die Methode ohne Lambda-Ausdruck aufzurufen? –