I’m trying to create a REST service to manage some DB tables, so because I’m new to C# and .NET I start by reading a tutorial, I came across this good starting point tut
http://www.codeproject.com/Articles/426769/Creating-a-REST-service-using-ASP-NET-Web-API
it shows how I can create some controller that handle in this case a simple tasks list, so I thought to create one controller for each table and implement the GET, POST, PUT, etc for each table
my question now is in the Global.asax.cs file at the end I have this
GlobalConfiguration.Configuration.ServiceResolver.SetResolver
(
t =>
{
if (t == typeof(TasksController))
{
return new TasksController(new TaskRepository());
}
return null;
},
t => new List<object>()
);
which initialize my dependencies, but…
first, for some reason (I think it have to do with the framework versions) the ServiceResolver class doesn’t exist why?? and
second even if exist how I need to write the code to create and initialize the rest of the controllers??
t =>
{
if (t == typeof(TasksController))
{
return new TasksController(new TaskRepository());
}
if (t == typeof(OtherController))
{
return new OtherController();
}
if (t == typeof(OneMoreController))
{
return new OneMoreController();
}
return null;
}
perhaps??
thanks for any help on this!!
That code is badly outdated. It’s based on a preview release of Web API. In the final version of Web API, the correct configuration hook for dependency injection is