C# - Class Encapsulation With Repository Pattern?

Oct 18, 2010

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?

I am using C# in ASP.NET 2.0

View 2 Replies


Similar Messages:

Pattern For Retrieving Complex Object Graphs With Repository Pattern With Entity Framework

Oct 13, 2010

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?

View 2 Replies

MVC :: How Should Use The Service/repository Pattern

Dec 8, 2010

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.

View 3 Replies

Can The Repository Pattern Work Well With Webforms

Mar 8, 2011

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?

View 2 Replies

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.

View 2 Replies

Architecture :: Repository Pattern - Pros And Cons?

Jul 8, 2010

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?

View 6 Replies

Architecture :: Data Validation In Repository Pattern?

Dec 21, 2010

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.

View 1 Replies

MVC2 LINQ - Repository Pattern, Where Should The Pagination Code Go

Nov 2, 2010

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):

[code]....

View 2 Replies

Using Multiple ObjectContexts In Entity Framework 4 With The Repository/uow Pattern

Jan 17, 2011

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 ...

IRepository<MyPocoObject> ds = ObjectFactory.GetInstance<IRepository<MyPocoObject>>();

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.

View 1 Replies

Architecture :: Provider Model Versus Repository Pattern

Feb 4, 2011

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?

View 1 Replies

The Model-Repository-Service-Validator-View-ViewModel-Controller Design Pattern

Jan 19, 2010

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?

View 2 Replies

Trying To Create A Repository Class For Each Table

Dec 17, 2010

I am trying to create a repository class for each table. For example I have TableA, TableB and TableC. TableB and TableC has Foreign key to TableA. I created an interface for TableA, TableB and TableC with SaveData() and ListData(). I have MVC form which inserts the data into these tables. When implementing these interface methods do I have to create a seperate class for each interface? Please let me if I am doing right.

[code]....

View 2 Replies

Architecture :: Singleton Pattern And Abstract Class?

Aug 19, 2010

I know what Singleton Pattern means and Abstract class means.What I wanted to know was how would this apply to real world.Could anyone give me any good example or simple explanation.Say I have a simple website, why would I use any of the above if any.Why would it simplify my architechture.

View 3 Replies

MVC :: Custom Ex Class Be In The Repository Layer Or The Domain Layer?

May 6, 2010

My repositories throw exceptions (System.Exception) when some things go bad and I know this is bad practice.. so i will create a custom exception (DataException). My question is should this custom ex class be in the repository layer or the domain layer? Im thinking it should be in Domain layer where all business objects and repository interfaces live but just want to make sure.

View 3 Replies

MVC :: AsyncController Gripes / Working Pattern For Converting A GET-POST-GET Pattern To Asny?

Feb 23, 2010

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.

View 5 Replies

C# - Abstraction And Encapsulation In Asp.net?

Mar 13, 2010

when we write all our application methods and variables in a classes is nothing but data abstraction and encapsulation.Is it right?

View 2 Replies

Best Design Pattern For Associating Subdomain With Area And PRG Pattern?

Aug 21, 2010

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 &#8594; 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.

View 2 Replies

Architecture :: Differentiate B.w Abstraction And Encapsulation?

Feb 14, 2011

I cannot differentiate b.w Abstraction and Encapsulation.Could anyone explain diff b/w these two together with some c# examples?

View 9 Replies

Architecture :: Encapsulation Doubt In The Code?

Nov 26, 2010

I am using code like this in Business Logic.Can u explian the below whether i am using Encapsulation concept in the below code.Also tell me why i should use private for declaring variable _Region and public for the property Region


private string _Region;

public string Region
{ [code]....

View 5 Replies

Override The Methods + Role Of Abstraction And Encapsulation?

Jan 4, 2011

1. Why we need override the methods? (i know what is ovwrriding but why ?)I gave answer to extend the functionality of method is it right ? again sub question was ,

Class A
{
method1()[code]....

if i can create the object of Class A in class B and can invok the method then why need to override metho here ? in fact i could not get this question , because i think both concept are irrelevat with each other. why he asked this ?same for overloading.

why we need overloading?If MSIL is there then what is need of CLS(common language runtime ) and CTS(common type system)List the 5 resposibilities of CLR (I explained only CTS,CLS,Garbage collection) was i right . what else?

What is role of abstraction and encapsulation? what the difference between them ? In which situation we have to devlop abstration and encapsulation.


6.What is included in signatures , when we said overloading means same name but different in signature. Is access modifiers included?

7.What is asp.net application life cycle?

8.Let say I am requesting for web application first time (genuine first time), how the request will executes? how IIS will know that for which application is this request is ?

9.If interfaces have empty methods (implicit abstract method) then what is its need? why we say it is reduces the code and provide reusability ?

10.In which scenario we need to implement interfaces?

11.In which circumstances we need to develop abstract classes?

12.Is class is static, means we can not create its instance, we can not derive it then how can we use method containing it? Why we need static classes?
Please guide me about these all question

13 What are the http handlers. http modules? who handle the request and resposes? why need of httpcontext ? what are the limitations of http handler, httprequest, httpcontext, httpresponse.

View 4 Replies

Architecture :: Should The Unit Of Work Point To The Service Layer Or The Repository And Then The Repository Point To The Service Layer

Jan 26, 2011

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..

[URL]

What would be better ?

View 11 Replies

MVC - BLL And DAL To Repository Design?

Feb 8, 2011

We are moving from ASP.NET Web Forms to MVC 2.0. In most of our projects we have a typical setup to communicate with a database.

Common (objects/entities like 'SiteMenu' and 'Users')

Business Logic Layer (with calls to de Data Access Layer)

Data Access Layer

The DAL has a DatabaseHelper with common database operation, an OdbcHelper with database specific operations (eg MySQL) and a StoredProcedure class with all the stored procedures.

How is this design translated into a repository design? We want to use our own database helpers instead of NHibernate etc.

View 1 Replies

MVC :: Using More Than One Repository In The Same Controller?

Nov 21, 2010

I have 2 repository that I'm trying to use in the same controller and cant find out how

This is what I'm tried :

[Code]....

for the first one it was working(VortRepository but I cant add the second )

View 5 Replies

ADO.NET :: Trying To Create A Data Repository And Using L2S For The ORM?

Feb 7, 2011

i am trying to create a data repository and i am using L2S for the ORM.

I have created a stored procedure called sp7DayAnalysisByStock which accepts a string parameter and returns a recordset of data rows. iThe result is a set of PriceList objects which is already available in the dbml.

What i now want to is create a data repository class with the signature below;

public IQueryable<PriceLists> Get7DayStockAnalysis(string stockname)
{
}

it seems what is being returned is ISingleResult..How can i return EITHER IQueryable<PriceLists> or any IList?

View 5 Replies

MVC :: Setting Up Repository Without LINQ?

Mar 4, 2010

I'm used to working directly with SQL and do NOT want to use Linq.

Pretty much I always create a class like the one below and have all the functions/methods necessary to perform a task.

How would I set up a repository without using LINQ??

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;

[Code]....

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved