views:

97

answers:

3

Although I believe I have a good grasp on MVC (from Rails), I'm learning the "MS Way" with ASP.NET MVC.

Also, I am learning Entity Framework as well.

I've created an Entity called User in my Models folder. Using LINQ to EF I can retrieve records and all is good.

Now, I want to put some business (or what I call, domain) logic in. But in my mind, EF is more of the DAL. So I created a folder called "Domain" and in there, I created a class for some business rules.

One of them is to encrypt passwords.

So I can use the following in my controllers:

string password = Domain.User.EncryptPassword(string salt, string password);

Also, that means the domain logic can access the EF User when it needs to persist to the DB.

Is this logic sound?

Any recommendations appreciated.

Thanks!

+2  A: 

The only thing I would ask is: "Why would a user, a person, know how to encrypt or hash a password?"

Encrypting a password would be part of an Application layer. This is almost anti-DDD.

jfar
I wouldn't encrypt passwords. I made a typo when asking.
cbmeeks
@cbmeeks - Answer stays the same. Thats an application layer concern.
jfar
+1  A: 

Hi! I think what you are looking for is POCO (Plain Old CLR Objects). In one hand you have your EF entities. In the other hand you have your Domain or Business Entities... and then you can map them... your DAL Layer must return POCO entities and not EF entities.. at least that's how is made in a 3-tier application. I suppose it's the same approach in a MVC application...

Am I right?

pabloide86
+1  A: 

It depends a bit on the project, but generally we:

  • do not put any code in the EF models, all models are stored in a seperate project
  • place a business layer between the MVC code and EF. In previous versions of EF this would be used to map EF objects to domain objects, but with POCO this is no longer needed. Any caching would be done in this layer.
  • use a helper or utility class for encryption
Shiraz Bhaiji