I've writen a custom WebViewPage implementation with a couple extra properties that I've annotated like so:

[Dependency]
public Tenant CurrentTenant { get; set; }

In a view inheriting from this (Shared/_Layout, if it matters), I have a reference to @CurrentTenant.Name.

I've written a custom implementation of IViewPageActivator that does this for Create:

var obj = this._container.Resolve(type);
return obj;

I put a breakpoint here and can see that this is getting called and that the property is getting injected correctly when I inspect obj... and yet the page throws an NullReferenceException on my attempt to access properties of CurrentTenant! What's going on here?

edit: I've found that this behavior is not an issue if I try to inject the information into a "regular" view instead of the layout.

有帮助吗?

解决方案

I found someone else had this problem when I understood better what I was looking for.

Anyway, it looks like none of the options here are appealing. I inserted this into the top of my _Layout.cshtml, but I'd love if someone knew of a better way to do it:

@{
  this.CurrentTenant = UnityConfig.GetConfiguredContainer.Resolve<Tenant>(); //and so on
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top