我在NinjectWebCommon.RegisterServices方法中为HttpContextBase创建了一个绑定,但是当我尝试在我的控制器或服务中引用它时,我收到一条错误消息.
这是绑定:
kernel.Bind<HttpContextBase>().ToMethod(context => new HttpContextWrapper(HttpContext.Current)).InRequestScope();
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
Error activating HttpContextBase
More than one matching bindings are available.
Activation path:
2) Injection of dependency HttpContextBase into parameter abase of constructor of type HomeController
1) Request for HomeController
Suggestions:
1) Ensure that you have defined a binding for HttpContextBase only once.
Run Code Online (Sandbox Code Playgroud)
如果我删除绑定,那么它似乎做我想要的(解析为HttpContextWrapper),但我想知道如何注册?
我相信AutoMapper在将对象列表从一种类型映射到另一种类型时使用缓存.看看下面的代码:
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Mapper.CreateMap<Source, Destination>()
.ForMember(dest => dest.SomeOtherNumber, opt => opt.Ignore());
Mapper.AssertConfigurationIsValid();
var sourceList = new List<Source>();
var s1 = new Source {SomeNumber = 10};
var s2 = new Source {SomeNumber = 69};
sourceList.Add(s1);
sourceList.Add(s1);
sourceList.Add(s1);
sourceList.Add(s2);
var destList = Mapper.Map<List<Source>, List<Destination>>(sourceList);
destList[0].SomeOtherNumber = 100;
destList.ForEach(x => Console.WriteLine("SomeNumber: {0}, SomeOtherNumber: {1}", x.SomeNumber, x.SomeOtherNumber));
Console.ReadLine();
}
}
public class Source
{
public int SomeNumber { get; set; }
}
public class Destination …
Run Code Online (Sandbox Code Playgroud) 我理解对于我通常称为"角色"或"权限"的事物的声明的用法.我知道声明更为通用,但从我在实践中看到的情况来看,它通常归结为:如果用户有这组声明,他们可以访问某些区域或执行某些功能.
想象一下wiki应用程序.你可能有一个content_contributor要求,将允许用户添加的内容,一个content_admin要求,将允许用户删除内容和modify_user要求,将允许参与者权限其他用户发放.
将此示例更进一步,我可能希望限制用户,以便他们只能看到自己或他们的团队创建的内容.
如果用户只能看到他们自己创建的内容,我们是否会对他们创建的每个内容提出索赔,或者我们是否会将该授权委托给该应用程序?
我想使用Roslyn CTP创建一个解决方案(.sln)文件,然后在解决方案中添加一些新项目.这是否可以使用当前的CTP,如果可以,您是否可以提供一个简短的代码片段来说明如何做到这一点?
我有以下类定义:
public class Registry
{
private List<Action<IThing>> _thingActions = new List<Action<IThing>>();
public Register<TDerivedThing>(Action<TDerivedThing> thingAction)
where TDerivedThing : IThing
{
// this line causes compilation issue
_thingActions.Add(thingAction);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么会出现这种抱怨它不能分配Action<TDerivedThing>
到Action<IThing>
了,我应该如何去解决呢?
我正在回到Java世界,我正在尝试使用JPA,Hibernate和PostgreSQL配置一个新的Spring Web应用程序.
我发现了许多带有各种XML配置文件的旧示例,我想知道是否有一种首选的新方法来执行此配置而不依赖于XML文件创作.
我需要配置的一些东西是hibernate sql方言,驱动程序等.