Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:59:51+00:00 2026-05-22T21:59:51+00:00

I am trying to make my first generic repository. I am starting with the

  • 0

I am trying to make my first generic repository. I am starting with the real simple ones but I am unsure how to hook it all up to ninject and use it through constructor injection.

   public class NhibernateRepo<T> : INhibernateRepo<T>
    {
        private readonly ISession session;

        public NhibernateRepo(ISession session)
        {
            this.session = session;
        }

        public void Commit()
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                transaction.Commit();
            }
        }

        public void Delete(T entity)
        {
            session.Delete(entity);
        }

        public void Update(T entity)
        {
            session.Update(entity);
        }

        public T Get(object id)
        {
            return session.Get<T>(id);
        }

        public T Load(object id)
        {
            return session.Load<T>(id);
        }

        public void ReadOnly(object entity, bool readOnly = true)
        {
            session.SetReadOnly(entity, readOnly);
        }

        public void Evict(object entity)
        {
            session.Evict(entity);
        }

        public object Merge(object entity)
        {
            return session.Merge(entity);
        }
    } 

public interface INhibernateRepo<T>
    {
        void Commit();
        void Delete(T entity);
        void Update(T entity);
        T Get(object id);
        T Load(object id);
        void ReadOnly(object entity, bool readOnly = true);
        void Evict(object entity);
        object Merge(object entity);
    }
}

Now I want to use this in my service layer. So I was trying to do

public MyServiceLayer(INhibernateRepo nhibernateRepo)

But it does not like that so I tried

public  MyServiceLayer(INhibernateRepo<T> nhibernateRepo)

but it could not find T.

So how do I do this? I am guessing doing the binding will be a challenge too so I am unsure how to do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:59:52+00:00Added an answer on May 22, 2026 at 9:59 pm

    Try moving <T> from interface-level to method-level. Like so:

    public void Delete<T>(T instance) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make my first app for Microsoft Surface. I need to use
Im trying to use generic types for the first time in Java , as
I'm trying to make a simple substring search using the brute force technique but
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
I am trying to make my first app using XNA, and I am having
Hi I'm trying to make the first element of my observableArray hidden, the following
It's my first time trying to make anything really interesting in C# and I
I am trying to make two .exe files in c where first one store
I'm trying to make a multiplayer game for the first time on Android. I
I'm trying to make a Jquery plugin ( findFirst() ) to find the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.