Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some sample example with parameterized constructor using reprository and web-API

What I have tried:

I tried this:

C#
public class TestUsersUserControlController : ApiController
{
    private readonly IConnectUserRepository ConnectUserRepository;
       
    public TestUsersUserControlController()
    {
    }

public TestUsersUserControlController(IConnectUserRepository ConnectUserRepository)
{
    this.ConnectUserRepository = ConnectUserRepository;.........this parameterized constructor is not hitting and getting always null
}
Posted
Updated 28-Jun-17 4:19am
v2

1 solution

For that to work you need to use Dependency Injection (DI). If you google "web api dependency injection" you'll find lots of examples, it might help if you know the DI framework you want to use in advance (Castle Windsor, Autofac, Ninject, Unity etc), however her is the MS docs which uses Unity

Dependency Injection in ASP.NET Web API 2 | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900