0

I'm designing an in-house enterprise application to manage small business loans using ASP.NET (C#), nHibernate, and an SQL Server in the back.

From much of the reading I've done, it seems to be fairly common practice to have separate repositories (as well as separate Service layer objects) for each domain object - which just seems like a lot of overkill and overhead to me.

With that in mind, I have a basic repository interface and a generic repository class based off of that to be used for domain objects that don't have 'special requirements' other than the basic CRUD operations (which are handled using ISession and ITransaction, code omitted)

// Repository interface:
public partial interface IRepository<T>
{
    void Add(T entity);
    void Update(T entity);
    void Remove(T entity);
    ICollection<T> GetAll();
    T GetByKey(int _ID);
}

// Generic repository - basic CRUD for most domain objects
public partial class BaseRepository<T> : IRepository<T>
{
    protected ISession session;
    ...

    public virtual void Add(T entity)
    { ... }
    public virtual void Update(T entity)
    { ... }
    public virtual void Remove(T entity)
    { ... }
    public virtual ICollection<T> GetAll()
    { ... }
    public virtual T GetByKey(int _ID)
    { ... }
}

As stated, rather than having code for a couple dozen repositories with pretty much identical code other than the <type>, I would like to be able to use this BaseRepository class as the business object for an ObjectDataSource, but it is not showing up as an available option in the 'Configure Data Source' dialog.

Is it even possible to use a generic for this purpose? For any ASP.NET MVC gurus out there - is this something that is more easily handled using that framework over just ASP.NET?

2
  • Any reason why you left c# out of the tags? I think the question would get more attention with it. Commented Jan 23, 2013 at 1:21
  • Added - thanks for the tip. Hopefully that helps! Commented Jan 23, 2013 at 18:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.