题
我正在尝试使用RavendB添加Bootstrap Nancyfx,我正在运行以下错误尝试运行应用程序...
“无法解决类型:nancy.iresponsefatter”
环境:
asp.net
nancy
nancy.hosting.aspnet
Ravendb
vs2010 developmenterver
代替粘贴所有代码,这里是我用作示例的站点的链接。按示例,我的意思是我将它复制逐字看,看看我是否可以才能工作。 http://stuff-for-geeks.com/category/nancyfx.aspx
我实际上看到了这个代码以前在演示中运行,但我出于某种原因无法让它全部运行。它在启动时失败了。几乎就像南希没有使用我的引导者一样。
更多堆栈跟踪:
[typeItializationException:'nancy.hosting.aspnet.nancyhttperheasthandler'raifight.namenthttperheSther'抛出异常。] nancy.hosting.aspnet.nancyhttproquesthandler ..ctor()+0
[targetInvocationException:调用目标已抛出异常。]
任何帮助将非常感激。
解决方案
That code is based on an older version of Nancy. You should be looking at using the IResponseFormatterFactory instead. The custom module builder, that is defined in the blog post, is based on an old copy of the DefaultNancyModuleBuilder and if you have a look at the current version https://github.com/NancyFx/Nancy/blob/master/src/Nancy/Routing/DefaultNancyModuleBuilder.cs you should be able to make the necessary adjustments
其他提示
Here is the code for the RavenAwareModuleBuilder
class under discussion:
Edit 1
The code below has been updated for Nancy Release 0.12. Note the new NegotiationContext
lines in BuildModule method.
public class RavenAwareModuleBuilder : INancyModuleBuilder
{
private readonly IViewFactory viewFactory;
private readonly IResponseFormatterFactory responseFormatterFactory;
private readonly IModelBinderLocator modelBinderLocator;
private readonly IModelValidatorLocator validatorLocator;
private readonly IRavenSessionProvider ravenSessionProvider;
public RavenAwareModuleBuilder(IViewFactory viewFactory, IResponseFormatterFactory responseFormatterFactory, IModelBinderLocator modelBinderLocator, IModelValidatorLocator validatorLocator, IRavenSessionProvider ravenSessionProvider)
{
this.viewFactory = viewFactory;
this.responseFormatterFactory = responseFormatterFactory;
this.modelBinderLocator = modelBinderLocator;
this.validatorLocator = validatorLocator;
this.ravenSessionProvider = ravenSessionProvider;
}
public NancyModule BuildModule(NancyModule module, NancyContext context)
{
context.NegotiationContext = new NegotiationContext
{
ModuleName = module.GetModuleName(),
ModulePath = module.ModulePath,
};
module.Context = context;
module.Response = this.responseFormatterFactory.Create(context);
module.ViewFactory = this.viewFactory;
module.ModelBinderLocator = this.modelBinderLocator;
module.ValidatorLocator = this.validatorLocator;
context.Items.Add(
"IDocumentSession",
ravenSessionProvider.GetSession()
);
module.After.AddItemToStartOfPipeline(ctx =>
{
var session = ctx.Items["IDocumentSession"] as IDocumentSession;
if (session != null) session.Dispose();
});
return module;
}
}