Does EF 6 allow dependency injection in my entities? Below is an example of what is needed.
class User
{
private IPasswordEncryptor _passwordEncryptor;
public User(IPasswordEncryptor passwordEncryptor)
{
_passwordEncryptor = passwordEncryptor;
}
...
}
So, I need to find a way to inject the IPasswordEncryptor into User in Entity Framework. It's a general question, I just provided an example above.
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.
Quoted from a post by Jimmy Bogard. Find that post (which includes an example) here: http://lostechies.com/jimmybogard/2010/03/30/strengthening-your-domain-the-double-dispatch-pattern/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With