Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a ASP.NET MVC4 project in which I would like to use the SimpleMembership. The application has a Person table that holds relevant information about users in the system.

I would like a link between the currently logged in user and the Person information. So I have made a foreign key in the Person table to the UserId column of UserProfile table (from SimpleMembership).

I use Entity Framework 5 as ORM and have implemented a generic repository to handle CRUD methods and so on.

Now I am at a point where I want to implement user profile creation. The creation consists of 2 parts parts:

  • login: username and password (to be stored in SimpleMembership tables)
  • personal information (to be stored in Person table)

In order to create a user I guess I need to:

  1. Save user information through SimpleMembership
  2. Save personal information together with userId from step 1 through my PersonRepository

I would like some kind of UserRepository that could save SimpleMembership data but I do not know if it's the right approach? Is there a better approach?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I always keep repositories so there a is a one to one relationship between a repository and a table in a database. And repositories do not know about other repositories. If you need to handle transactions between repositories I would implement a Unit of Work design pattern and on top of that a Service design pattern that handles the domain logic around the transactions.

Another option is to modify the UserProfile in SimpleMembership to contain the extra information that you have in the Person table. UserProfile was designed to be customized and you can read about customizing it here.

share|improve this answer
    
If I take the Unit of Work approach - how will data be inserted into the webpages_* tables? Would it be correct to use WebSecurity calls in my repository? –  user1632306 Feb 28 '13 at 9:57
    
You would not make WebSecurity calls from a repository. Those calls would be made from the Service layer. The WebSecurity API is a Service layer. Service layers can all other Service layers. You would wrap each of your custom tables in a repository. Then the repositories in a single unit of work, which is managed by a service layer. If your service layer is tightly coupled with the WebSecurity it could be called from this layer. –  Kevin Junghans Feb 28 '13 at 14:17
    
Thanks - I will take that approach –  user1632306 Mar 1 '13 at 11:59

You could wrap this functionality up as a service.

In the service you would use both the SimpleMembership api and your own repository code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.