gpt4 book ai didi

entity-framework - EF : Entity Dependency injection

转载 作者:行者123 更新时间:2023-12-04 08:35:53 24 4
gpt4 key购买 nike

EF 6 是否允许在我的实体中进行依赖注入(inject)?以下是所需内容的示例。

class User
{
private IPasswordEncryptor _passwordEncryptor;

public User(IPasswordEncryptor passwordEncryptor)
{
_passwordEncryptor = passwordEncryptor;
}

...
}

所以,我需要找到一种方法将 IPasswordEncryptor 注入(inject)到 Entity Framework 中的用户中。这是一个普遍的问题,我只是在上面提供了一个示例。

最佳答案

For those using a DI container, you might try to inject the dependencies into the aggregate root. That leads to a whole host of problems, which are so numerous I won’t derail a perfectly good post by getting into it. Instead, there’s another, more intention-revealing option: the double dispatch pattern.



引自 Jimmy Bogard 的帖子。在此处找到该帖子(包括示例): http://lostechies.com/jimmybogard/2010/03/30/strengthening-your-domain-the-double-dispatch-pattern/ .

关于entity-framework - EF : Entity Dependency injection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18032517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com