I am using web api project with Entity framework and i was planning to make the Entity Framework as dynamic one [ change the connection string at run time]
In a normal MVC application i did this like
public class ApiRepository
{
public WebApiLabDbEntities dbContext;
public ApiRepository()
{
string connection_string = (string)(System.Web.HttpContext.Current.Session["Connection"]);
if (String.IsNullOrEmpty(connection_string))
{
dbContext = new WebApiLabDbEntities();
}
else
{
dbContext = new WebApiLabDbEntities(connection_string);
}
}
}
But in a webapi project i cant set the connection string in a session object like Session["Connection"]
So what is the alternative way to achieve the same? The web api is going to use token based authentication and the auth_token decides the connection string to be used.