Solved

seperating read and write functionality in my repository

Posted on 2012-03-21
11
339 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

864 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

20 Experts available now in Live!

Get 1:1 Help Now