I am writing my first ASP.NET Web API application. I am familiar with other web application frameworks (mostly Symfony, but also Django, and to a lesser extent RoR).
I am struggling a bit, to understand the sequence of events that occur after a request is sent from a browser/front end client, to the web server.
I am writing a multi tenanted application, which uses a DB backend. I am using ADO and raw SQL to access the database, I also need to store a lot of information, per user, so that basically, I create (or fetch from cache), a preloaded context, for the user.
here is some pseudo-code, that illustrates, what I'm trying to achieve, in ASP.NET.
namespace myApp.Controllers
{
public class FoobarController : ApiController
{
public Response doLogin(request)
{
var ctx = myApplicationContext.getInstance();
var user = ctx.getUser();
if (!user.isLoggedOn())
{
username = request.getParameter('username');
password= request.getParameter('password');
dbManager = ctx.getDbInstance();
resp = dbManager.internalLogin(username, password);
// Load permissions etc for current user, from db
// Store user info in cache ..
}
}
public Response ActionOne(request)
{
ctx = myApplicationContext.getInstance();
user = ctx.getUser();
if (user.hasPermission('xxx'))
{
}
}
}
}
My question, is, how do I implement this kind of functionality:
Namely:
Create an application context, in which I can populate with context sensitive information like a database connection, mailer configuration, object factories, miscellaneous state information etc.
Access a user object (which I can add user credentials, permissions etc to)
Have access to session variables etc?
Notes
- I will be deploying the web app on Linux, and I will be using Apache as the web server.
- For the purpose of this project, I don't want to use any Microsoft technology like Azure, Windows Authentications etc (other than C# and ASP.Net)
- I want to use a raw database connection, not using Entity Manager (legacy application port)