Splitting Out Membership And Using The Repository Pattern
Feb 15, 2010
I am building an application using asp.net mvc, DI, IoC, TDD as a bit of a learning exercise.
For my data access I am using the repository pattern. Now I am looking at membership and how this can work with the repository pattern. I am currently using a Linq to Sql repository but don't want to be tied to SQL Server for membership.
Secondly, I am looking to split out membership into a number of services:
AuthenticationService - identify the user
AuthorizationService - what can they do
PersonalizationService - profile
The personalization service will be what really defines a "customer" in my application and each customer will have a unique id/username that ties back to the AuthenticationService - thus, allowing me to use the default ASP.NET Membership provider, roll my own or use something like Open ID.
Is this a good approach? I don't want to reinvent the wheel but would rather these important parts of my application follow the same patterns as the rest.
We have an ASP.NET MVC site that uses Entity Framework abstractions with Repository and UnitOfWork patterns. What I'm wondering is how others have implemented navigation of complex object graphs with these patterns. Let me give an example from one of our controllers:
[code]....
It's a registration process and pretty much everything hangs off the POCO class Person. In this case we're caching the person through the registration process. I've now started implementing the latter part of the registration process which requires access to data deeper in the object graph. Specifically DPA data which hangs off Legal inside Country.
The code above is just mapping out the model information into a simpler format for the ViewModel. My question is do you consider this fairly deep navigation of the graph good practice or would you abstract out the retrieval of the objects further down the graph into repositories?
i'm new to asp.net MVC, and I'm trying to understand the service/repository pattern and how to best implement it.
I've followed the MVC Music store tutorial, and it suggests that the public partial class ShoppingCart implements an AddToCart method looking like this:
[Code]....
Now if I would like to use the service/repository pattern in a correct way, should I just replace the row "storeDB.AddToCarts(cartItem)" with something like cartService.AddToCarts(cartItem) and then just save the added row by calling cartService.Save() instead of shopDB.Save()? The methods AddToCart(...) and Save() in cartService then calls the repository that does the actual saving.
I've been using MVC for the last year and unfortunately I am stuck adding features to an existing web forms site. The site makes heavy use of inline SQL and it is kind of all over the place. Using an ORM is not going to happen either and wouldn't address the problem of keeping queries all in one place.
Can the Repository Pattern and Service layers also work well with classic asp.net web forms?
I am sort of using a repository pattern to extract information from a database. I have two classes, report and reportRepository.
The trouble I have is that since reportReposity has to fill in all the details for the report object, all the members in the report have to be publicly accessible.
Is there a way so that I can ensure that only the repository class can access some of the methods of the report class and only it can set some of the properties that other classes cannot, sort of like what friend does in c++. Or is there a completely different way of handling this situation?
This is possibly the worst kind of religious debate -- a religious debate with practical consequences. But it's one that needs to be had, and I can't seem to fit it in my tiny head. Here are the pros and cons of the pattern as I know them:
Pros:
-Encourages DRY (don't repeat yourself) design in that identical queries are written only once per set of query conditions -Facilitates unit testing by allowing itself to be abstracted into an interface -Creates an opportunity for business-level validation
Cons:
-Breaks DRY philosophy in that you're generally repeating your database schema -In a sense breaks separation of concerns, because the query concerns of the controller and view frequently become the concerns of whoever is maintaining the repository -Determining what should be a repository and what should be returned as a raw associated ORM entity becomes an ambiguous art
To me it seems like all this stuff should be done at the ORM level, but Entity Framework has much fewer hooks than Linq to Sql does, yet Entity Framework tends to be regarded as being more robust, so it seems that this is by design, and that the designers of EF are in fact encouraging another layer. Are there any tools or anything that I could be using for this? Am I missing something?
I am currently using the 3-tier Repository pattern in my application. Actually it's the first time for me to implement a design pattern at all! i used to put all my code in the so called now presentation layer.
i want to implement data validation, for example, password should not be more than 10 characters and have to contain special characters. Should i put this code in the data access layer? but my data access layer contains methods that take the DTO as a parameter for example
[Code]....
and the same is for other CRUD operations (DELETE and UPDATE), so implementing such validation on the DAL would make me duplicate the code in each and every method that accepts the DataObject as a paramter. Same holds for the business logic layer where i am using it as a proxy between the presentation and the data access layers.
Eventually it has to use the same Data Objects as parameters. This only leaves me with one option which is to do the validation on the Data Object part. But i think this is not the essence of the respository pattern which states that the Data object class should only be a "container" class with no behavior.
I'm working on adding an HtmlHelper for pagination, but I am unsure where the proper and/or most beneficial place to put certain parts of the pagination code from a performance and maintainability standpoint.
I am unsure if the Skip(), Take() and Count() portions of Linq to SQL data manipulation should live within the repository or the controller.
I am also unsure if their order and where they are used affects performance in any way.
If they live within the repository from my understanding this is how it would work:
1. I would pass the pageIndex and pageSize as arguments to the repository's method that grabs the data from the database. 2. Then grab the full data set from the database. 3. Then store the count of TotalItems of that full data set in a variable. 4. Then apply the Skip() and Take() so the data set retains only the page I need. 5. Display the partial data set as a single page in the view.
If they live in the controller from my understanding this is how it would work:
1. I would grab the full data set from the repository and store it into a variable inside of the controller. 2. Then get the count of TotalItems for the full data set. 3. Then apply the Skip() and Take() so the data set retains only the page I need. 4. Display the partial data set as a single page in the view.
Inside the controller (I realize I will incorrectly get the page count here and not TotalItems):
i am using EF4 and StructureMap in an asp.net web application. I am using the repository/unit of work patterns as detailed in this post. In the code, there is a line that delegates the setup of an ObjectContext in global.asax.
EntityUnitOfWorkFactory.SetObjectContext(() => new MyObjectContext());
On the web page code-behind, you can create a generic repository interface like so ...
My question is what is a good approach to refactoring this code so that I can use more than one ObjectContext and differentiate between them in the code-behind? Basically i have two databases/entity models in my application and need to query them both on the same page.
I am trying to understand the fundamental differences between the Provider Model and Repository Pattern.
I have used the Provider Model in many many situations and am confident with it when designing applications. However, the more examples I encounter on the internet and asp.net evolution I keep coming across "Repository" Interfaces for classes that look like a Provider Model.
I have dug around a bit but all I can see is that they kinda do the same thing, or closely overlap by enforcing an inheriting class to adhere to a "contract" of implemented / abstracted methods etc...is there more to it?
When I first heard about ASP.NET MVC, I was thinking that would mean applications with three parts: model, view, and controller.
Then I read NerdDinner and learned the ways of repositories and view-models. Next, I read this tutorial and soon became sold on the virtues of a service layer. Finally, I read the Fluent Validation documentation, and I'll be darned if I didn't end up writing a bunch of validators.
Tonight, I took a step back and thought about what had become of my project. It seems to have become the victim of the design pattern equivalent of "feature creep". Somehow I'd gone from Model-View-Controller to Model-Repository-Service-Validator-View-ViewModel-Controller. You want loosely coupled and DRY? We got your loosely coupled and DRY right here! But I'm wondering if this could be a case of too much of a good thing.
Am I right to be concerned? Or is this actually not as crazy as it sounds? On one hand, it seems crazy to have so many layers. On the other hand, every layer has a clearly defined purpose that makes sense to me. Have your MVC applications turned into MRSVVVMC apps too? If not, what do they look like? Where's that right balance?
Does anyone have a working pattern for converting a GET-POST-GET pattern to asny?
I'm encountering the following issues:
1. You cannot mix Sync and Async action methods SubmitForm(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() ... (because the resolver gets all confused ... it doesn't use the HTTP verb to decide who to target. BTW: I think that's poor design, or a bug)
2. Renaming the get method name to something else eg: SubmitFormConfirmation(), SubmitFormAsync(bool? confirm), SubmitFormCompleted() would be very awkward if it works ... because you have to doctor the <form markup to specify an action name.
3. You cannot give them all async names SubmitFormAsync(), SubmitFormAsync(bool? confirm), submitFormCompleted(), because the call just keeps malfunctioning. It sometime even behaves as if you are requesting a delete of something.
Can someone give an insight from an actually working sample.
Now that the next version of ASP.NET MVC is being prototyped and previewed (ASP.NET MVC 3 Preview 1 came out a couple of weeks ago), I wonder if we should call the attention of the Core Dev team (S Hanselman, Phil Haack and all) to this "feature."there a easy/non tacky way of associating subdomains → areas?Something like: [URL]Also, whats the best accepted design pattern in implementing PRG pattern in ASP.NET MVC? I guess it should also get some official loving in MVC 3.
Just wondering, in an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?
Ive saw two example:
* One where the unit of work and repository both have an instance to the service layer..
Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable
Doesn't use a service layer but its obvious that one could be use in that case.
* Second where the unit of work have an instance to the repository which have an instance to the service layer..
I'm using C# and ASP.NET 3.5. Basically I'm retrieving a column of data from a dataset and putting this into a list like so:
List<String> dates = new List<String>(); foreach (DataRow rowMonth in myDS.Tables[0].Rows) { string ListedMonthYear = (string)rowMonth[0]; dates.Add(ListedMonthYear); }
The returned values are:
Apr-10 Mar-10 Feb-10 Jan-10 Dec-09 Nov-09 Oct-09
I'm interested in splitting these values into two lists with the idea of performing operations on them in the future.
Apr | 2010 Mar | 2010 Feb | 2010 Jan | 2010 Dec | 2009 Nov | 2009 Oct | 2009
What is the best way to do so?
EDIT: rowMonth is just the datarow that includes all date related values - the month-year, the month beginning, month ending, month active or inactive. Basically I'm just trying to extract that first column month-year to do operations on and ignore the rest.
The following is an example of using session state, which i can handle with a single variable. But this example uses. well you can see it. Where I am stuck is splitting the string into the three variables. Also, I am not too sure about the ; vs. a comma delimiter that usually see. I think it is a pretty old example. Session("Stocks") = "MSFT; VRSN; GE" ' Get Stocks, split string, etc. Dim StockString StockString = Session("Stocks")
For applications that need to have fastly different view layers, and I would like to still use the idea of the controller. I would ideally like to but the controllers in a Class Lib. and then have only the Views in a MVC Web Application. Taking the model out in this way works well, but I can't find a nice way to split the views and controllers.
I am trying to get all the words in a string using a regular expression.When I use this expression in javascript, it works, but when I try it in the .Net code I get the whole string.this is my code.Is my regular expression wrong or am I using the wrong method?
Code: Dim myRegex As New Regex("/([a-zA-Z]){1,1}([a-z])+/g") Dim str() As String = myRegex.Split(text)
I am working with the listbox and binding the data to the listbox. My question is if i retrieve 20 rows in a listbox then how can i arrange 10 rows on each column (splitting 10 rows side by side or dividing). sample:
Exact Data in a Listbox Looking for something like this: Listboxitem1 Listboxitem1 Listboxitem3 Listboxitem2 Listboxitem2 Listboxitem4 Listboxitem3 Listboxitem4
I have one more question. How can I display my data in a listbox as a treeview structure with a nodes. Or can i insert treeview inside listbox.
I'm using the commandArgument property of the LinkButton ( Which is wrapped inside a repeater ) to pass two values -as one string- to a second repeater then I try to split them into two values, So I could use them as parameters in my ADO.NET Code (SqlCommand Parameters)....after testing my queries don't return any results but If I passed fixed values for the parameter or change the source of the parameter (just for test from a textbox or querystring or something) I get my results, so I think the problem is in splitting.
I Conduct some arugment values from the ArgumentCommand property of the LinkButton -which is wrapped inside a repeater:
I have too many lines in my code behind file. Now it grows up to almost 3500 lines. I wonder if it can be splitted into several files.
To be specify, say I have CustomerEdit.aspx and code behind as CustomerEdit.aspx.cs. In my code behind, most of them are functions taking care of UI (i.e. protected void ... _Click() or protected void ... _SelectedIndexChanged()). I have some private functions, but they usually refer to some UI elements.
Question: Can I safely seperate CustomerEdit.aspx.cs into smaller files like CustomerEdit01.aspx.cs, CustomerEdit02.aspx.cs, etc?
I have a large string that I want to save in a cookie, however I don't know what the best practices are for max string length per cookie, and max cookie count. What logic should I use to split the string and later combine a set of cookies?
(Microsoft ADFS and perhaps Siteminder do this technique so I would be interested in what thier implementation is)
First of all, I'm relatively new to asp.net (3.5) and all of its controls. What I'm trying to do is to split up a detailsview. I have a submission form containing quite a lot of fields that are supposed to be filled out by the user. In my design I have a tabstrip with headlines about the different sections of the form. For example:
Tab1: Personal Info Tab2: Info about your car Tab3: Contact info
I have tested to add a new "user" via a DetailsView and it works. But what I want to do is to split up the contents within the <Field> tags In the DetailsView In different div classes (using css and javascript to hide/show the right tab contents). But when I try to do this Visual Studio says that characters like <p> and others aren't allowed within the Field tags, which makes sense. Is there any control to use for these kinds of situations?