Solved

seperating read and write functionality in my repository

Posted on 2012-03-21
11
344 Views
Last Modified: 2012-03-27
Hi,

I'm just getting to grips with using a repository and interfaces in c# and now have a new thought.

I'm about to start a reasonably sized website that has 3 sections. The public facing, the admin section and the client log in area.

Although it is probably over kill as I am likely to be the only one working on the site I'd like a go at doing this anyway.

What I want to do is split my functionality up so that the public facing website only has access to my read functionality, the client login only code relevant to its purpose and likewise with the admin section.

Am I right in thinking that the best way to do this is to have a generic read interface that a generic repository implements. The same then for the the public facing code and the private log in area?

Does that make sense?

Looking for some constructive input and direction....

Thanks in advance.
0
Comment
Question by:scm0sml
  • 4
  • 4
  • 3
11 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 37748792
Are you implementing the repository pattern?  You seem to be using the word repository alot so I want to make sure thats what you mean.  Are you planning on using webforms or MVC?  Answering those questions will help me contextualize what you are attempting to do a bit better.
0
 

Author Comment

by:scm0sml
ID: 37749057
Sorry yeah that's correct. Repository pattern with web forms.

Thanks
0
 
LVL 14

Expert Comment

by:binaryevo
ID: 37749136
You could do it the way you are talking about or have 3 seperate repositories.  What I usually do ( and where i have implemented it ), is in the context of a MVC application I create 3 areas, each with its own unique repository.  Repositories are sub patterns so you can create them where it makes sense.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 14

Assisted Solution

by:binaryevo
binaryevo earned 167 total points
ID: 37749286
After reading your question again, I think, due to the 3 distinct differences in what you are trying to accomplish, it makes sense here to use 3 different repository implementations.
0
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 333 total points
ID: 37751218
I would rather have something like this:-
public interface IEntity
{
public long Id{get;}
}

public interface IAggregateRoot : IEntity { }

public interface IRepository<TEntity>
                               where TEntity : class
{
public IUnitOfWork UnitOfWork{get;}
}

public interface IUnitOfWork
{
void commit();
void rollback();
}

public interface IReadOnlyRepository<TEntity> : IRepository<TEntity> 
                               where TEntity : class, IAggregateRoot
{
        TEntity this[long id] { get; }

        TEntity FindBy(long id);
        IList<TEntity> FindAll();
}

public interface IReadWriteRepository<TEntity> : IReadOnlyRepository<TEntity>
        where TEntity : class, IAggregateRoot
    {
        new TEntity this[long id] { get; set; }

        void Add(TEntity entity);
        void Update(TEntity entity);
        void Delete(TEntity entity);
    }

Open in new window


This is the sample framework that can be used.
I hope you are aware about tenets of Domain Driven Design.
0
 

Author Comment

by:scm0sml
ID: 37751263
Buggycoder so I'd need a read unit of work and a read write unit of work then is that correct?
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 333 total points
ID: 37751283
Unit of work is component that will take care of committing and rollback of your transaction.
As far as read is concerned, you will not commit or rollback.

so you can use it in case of Read-Write Repository only....

Also please Use DI(Dependency Injection) to pass it as a parameter of your repository concrete implementation.
0
 

Author Comment

by:scm0sml
ID: 37751685
Have you got a quick example of that?
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37751765
0
 
LVL 14

Expert Comment

by:binaryevo
ID: 37752631
BuggyCoder that's pretty slick... I Like it...
0
 

Author Comment

by:scm0sml
ID: 37753145
ok thanks.

One last thing.... when we say have a repository for different areas....

I may create the 3 repositories but there is nothing to stop a page in the public website creatuing an instance of the admin repos for example is there?

Would I have to build them into sepearet dll's for that?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question