I am working on a multi-tenant project in which each tenant have its own customers. Currently i am implementing a real time stuff in which whenever any customer get registered or existing customer edit his profile info i want to notify the tenant of that customer in real time (using signalR).
For detecting changes in customer table i am using SqlDependency and an SqlTrigger. Trigger will do the entry in the notification table (which basically contains some Ids (like TenantId, CustomerId) which get affected and some other info) and in an event fired by Sqldependency i am calling the method which will further calls the client method using signalR context.
Now my problem is that i can't access the HttpContext.Current thread in Sqldependency event it is null because no request happen for its execution. Check this image:
Please correct me if i am wrong. I want to access this HttpContext.Current because i want to access the current Tenant to notify. And my TenantProvider implementation gets the tenant from the Url Host.
So my first question is, there is any way to access the context in which the event function code is executing ??
If not then i have another option with some doubts. The option is that i am saving the Changes in Notification table which contains the TenantId, CustomerId etc info. I can access the notification with the latest timestamp and from that entry i can get the tenantId to notify.
Now the doubt if 2 or more customer get registered simultaneously and before accessing the latest timestamp notification entry, trigger enter other notification also than in that case we missed some notification.
So my second question is whether i am over-think on this or this really be a problem. If this is really be a problem then please let me know the solution ??