In any case, in order to get access to the current main person even before the request arrives at the controller using Simple Injector? I use OWIN and Asp.net identifiers.
I have a DbContext that I insert into my controllers, but this context will get a connection string based on the authenticated user. This is what I still have
container.RegisterWebApiRequest<TenantDbContext>();
container.RegisterWebApiRequest<ITenantConnectionStringProvider>(() => new TenantConnectionStringProvider(container));
Then in my TenantConnectionStringProvider I have this,
var request = container.GetCurrentHttpRequestMessage();
var principal = request.GetRequestContext().Principal as ClaimsPrincipal;
But the principal has no complaints. I realized that claims are only available after the controller has been created. Does this mean that it is simply impossible, because this step precedes the creation of the controller?
Edit: This is basically what the rest of the code does:
WebApi Controller
public CampaignsController(TenantDbContext context, ILog log)
{
this.campaignService = campaignService;
this.log = log;
}
( DbContext EF):
public TenantDbContext(ITenantConnectionStringProvider provider)
: base(provider.GetConnectionString())
{
}
, .
OWIN, . , , , TenantConnectionStringProvider, HttpRequestMessage.
app.Use(async (context, next) =>
{
using (container.BeginExecutionContextScope())
{
CallContext.LogicalSetData("Claims", context.Authentication.User.Claims);
var request = (OwinRequest)context.Request;
await next();
}
});
TenantConnectionStringProvider ,
public string GetConnectionString()
{
var context = (IEnumerable<Claim>)CallContext.LogicalGetData("Claims");
return "test";
}