[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

seperating read and write functionality in my repository

Posted on 2012-03-21
11
Medium Priority
?
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 14

Assisted Solution

by:binaryevo
binaryevo earned 668 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 1332 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 1332 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 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