Last post Aug 05, 2014 08:06 AM by jon_technegol
Aug 04, 2014 03:18 PM|jon_technegol|LINK
I am creating a multitenant application that will store the users data either in separate databases or a single database using a TenantId to query data.
I have got as far as the user being able to register using the asp identity framework and I store the tenantId and connection string info with the user and subsequently store this in a claims token.
My question is what's the best way to set this id and connection string dynamically. I have a Product repository that uses a base repository that creates the dbContext and sets the connection string. Do I just pass the Id and Connection String into the controller
and onto the Product repository and then onto the base repository from the claims token.
Any advice would be greatly appreciated.
Aug 04, 2014 09:17 PM|ignatandrei|LINK
You can modify the connection string before sending to repository
Aug 05, 2014 05:53 AM|pprasannak|LINK
Do I just pass the Id and Connection String into the controller and onto the Product repository and then onto the base repository from the claims token
Yes, I believe that is the right approach. Pass the connection string to the DBContext constructor. May be your code looks like this
public ProductRepository : BaseRepository
public ProductRepository(connectionstring) : base(connectionstring)
Public BaseRepository : DBContext
public BaseRepository(connectionstring) : base(connectionstring)
Aug 05, 2014 08:06 AM|jon_technegol|LINK
Thank you for the replies.
Yes my code will look very similar but that I have an Interface for the repository but I guess that just adds another layer.
You've given me the confidence that I'm on the right track this is all very new to me.