[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

seperating read and write functionality in my repository

Posted on 2012-03-21
11
Medium Priority
?
351 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

834 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