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 8923619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:10:30+00:00 2026-06-15T07:10:30+00:00

I have a web api set up to get companies from a data base.

  • 0

I have a web api set up to get companies from a data base.

namespace Bloginect.Controllers
{

public abstract class ApiControlerBase : ApiController
{
    protected BloginectUow Uow { get; set; }
}

public class CompanyController : ApiControlerBase
{
    // Dependancy set up with Ninject
    public CompanyController(BloginectUow uow)
    {
        Uow = uow;
    }

    // GET api/company
    public IEnumerable<Company> Get()
    {     
        *-------- Uow.companies is null here ----------*
        return Uow.companies.GetCompanies();
    }
}
}

I am getting a null exception for companies on the line

return Uow.companies.GetCompanies();

The unit of work class holds a company repository and it is set up as follows

namespace Bloginect.Data
{
public class BloginectUow : IDisposable
{
    private BloginectDbContext DbContext = new BloginectDbContext();
    public ICompanyRepository companies { get; set; }      

    public void Commit()
    {
        DbContext.SaveChanges();            
    }        

}
}

The company repository interfaceis set up as follows

public interface ICompanyRepository : IRepository<Company>
    {
        /// <summary>
        /// Gets companies
        /// </summary>
        /// <returns></returns>
        IQueryable<Company> GetCompanies();
    }

IRepository<Company>

is just a standard repository with crud operations

Can anyone see a problem and why is the ICompanyRepository not getting initiated.

  • 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-06-15T07:10:32+00:00Added an answer on June 15, 2026 at 7:10 am

    You need to initialize your repository. Take a look at the samples how could you do this:

    1º Solution – Not Generic implementation… you can do some specific and complex queries on this scenario for each entity.

    public class BloginectUow : IDisposable
    {
        private BloginectDbContext DbContext = new BloginectDbContext();
    
        public ICompanyRepository Companies { get; set; }      
    
        // constructor
        public BloginectUow()
        {
            // initialize your repository..
            Companies = new CompanyRepository();
        }
    
        /// methods...
    }
    

    In this case you have to have a class to implement your ICompanyRepository interface:

    public class CompanyRepository : ICompanyRepository {
    
       // methods of the interface to data access... from entity framework or nhibernate or ado.net or whatever...
    
    }
    

    2º Solution – Or, you could use an generic repository:

    public class BloginectUow : IDisposable
    {
        private BloginectDbContext DbContext = new BloginectDbContext();
    
        public IRepository<Company> Companies { get; set; }      
    
        // constructor
        public BloginectUow()
        {
            // initialize your repository with a generic implementation..
            Companies = new Repository<Company>();
        }
    
        /// methods...
    }
    

    In the second case, you have to have a Repository<T> class (which need to have CRUD operations… for sample) and use a interface of this class on your UnitOfWork.

    Doing this way, you will get a generic implementation of your DataAccess but you could not to do complex queries when you need. If you need to do complex queries I would recommend you to get a single implementation of Repository for each entity, inherits if from a generic repository and implement method to do complex queries, that’s a good pratice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Web API (GET): public class UsersController : ApiController { public
using Newtonsoft.Json; namespace FAL.WebAPI2012.Controllers { public class Person { public int Id {get;set;} public
I have a problem when serializing inherited objects in Web API. [DataContract] public class
I have a pretty standard asp.net web api set up with get post put
I have a Web API project with models that look like this: public class
I have this action in Web Api controller: public Data GetData(ComplexModel model) and model
I'm trying to return this class in web api: public IEnumerable<Product> Get() { var
I have trying to learn MVC4 Web API. I am running my project from
I have the following action in my ASP.NET Web API: public IEnumerable<Car> carssOfUser(int id,
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>

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.