Solved

seperating read and write functionality in my repository

Posted on 2012-03-21
11
336 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now