Rhino 安全和 POCO 类
看来如果我想在一个实体上使用Rhino Security,该实体需要有一个Guid类型的SecurityKey字段。我看到一个示例,其中实体类的构造函数有一条分配 SecurityKey 的语句,
public class Document
{
public Document() { SecurityKey = Guid.NewGuid(); }
public virtual int Id {get; set;}
public virtual string Name { get; set;}
public virtual Guid SecurityKey { get; set;}
}
public class DocumentInformationExtractor : IEntityInformationExtractor
{ .... }
构造函数每次都会分配一个新的 Guid SecurityKey。我不明白为什么这有效。难道它不应该只为尚未持久化的新实体分配一个新的 Guid 吗?
it seems if I want to use Rhino Security on an entity , that entity need to have a SecurityKey field of Guid type. I saw an example where the constructor of the entity's class has a statement that assign the SecurityKey
public class Document
{
public Document() { SecurityKey = Guid.NewGuid(); }
public virtual int Id {get; set;}
public virtual string Name { get; set;}
public virtual Guid SecurityKey { get; set;}
}
public class DocumentInformationExtractor : IEntityInformationExtractor
{ .... }
The constructor assgined a new Guid SecurityKey everytimes. I don't understand why this works. Should it not assgined a new Guid only for new entity that has not been persisted ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正确的。您必须这样做,否则保存的
Guid
将为{00000000-0000-0000-0000-000000000000}
,但您需要一个正确的非空 guid。该字段将在您调用时使用:
这只是使用,这样您就不会保存空的
SecurityKey
Guid,因为您将来可能会使用(如果您不这样做,则无需分配权限)需要他们)。 Rhino-Security 将负责图表的加载并使用保存的值填充SecurityKey
。That's right. You have to do that otherwise the
Guid
saved would be{00000000-0000-0000-0000-000000000000}
, but you need a proper, non-empty guid.This field will be used when you call:
This is just used so you do not save an empty
SecurityKey
Guid, cause you might use in the future (you do not need to assign permissions if you don't need them). Rhino-Security will look after the load of the graph and populateSecurityKey
with the one saved.