我遇到以下IronPython属性(RouteAttribute
)的问题:
import clr
import System
from System.Web.Http import HttpGetAttribute, ApiController, RouteAttribute
class DemoController(ApiController):
@RouteAttribute("~/api/test")
def test(self):
return "Hallo Welt!"
class DemoControllerClr:
def getType(self):
return clr.GetClrType(DemoController)
如果我创建DemoController-Class的实例,我总是收到错误消息:RouteAttribute is not callable
。我不会自己创建DemoController
的实例,asp.net web api 2会尝试这样做。
也许有人在IronPython中有一些属性的实验。
修改
我的目标是,混合C#和IronPython API-Controller。我这样注册控制器(c#的工作原理):
controller = new Dictionary<string, System.Web.Http.Controllers.HttpControllerDescriptor>();
controller.Add("General", new System.Web.Http.Controllers.HttpControllerDescriptor(config, "General", typeof(Controller.GeneralController)));
foreach (DBScript script in dbContext.LoadData<DBScript>(optWherePart: "ScriptContentType = 1"))
{
System.Diagnostics.Debugger.Launch();
var sc = ScriptManager.Singleton.CreateScript(script.ScriptName, ScriptLanguage.IronPython);
var clrInst = sc.GetClassInstance(script.ScriptName + "Clr");
controller.Add(script.ScriptName.Replace("Controller", ""), new System.Web.Http.Controllers.HttpControllerDescriptor(config,
script.ScriptName.Replace("Controller", ""), clrInst.getType()));
}
EDIT2
我使用的是最新版本的IronPython(2.7.5)。
谢谢!
答案 0 :(得分:0)
这不起作用,因为依赖注入机制不能与ironpython一起工作,因为dlr。所以就是不要工作。