1

I've inherited an ASP.NET MVC3 + NInject application and I'm tasked with implementing virtual private databases at the SQL Server level. In order for this to work the credentials used to connect to SQL need to change based upon user.

How does one pass session-specific information into the repository implementation layer? I would rather not add parameters to every service and repository call.

Currently the connection string is set from a web.config entry when the repository objects are created.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
dehart
  • 11
  • 2
  • 1
    Beats me. Your question is vague, doesn't contain any code showing your existing code, and doesn't adequately explain what you need. So.. good luck with that. – Erik Funkenbusch May 15 '12 at 20:31
  • can't you inject the database required at the controller level, assuming the repository is driven by an interface?? sounds like this is what the design was meant to handle unless i'm missing a detail that your brief description doesn't reveal – jim tollan May 15 '12 at 21:07
  • Found one possible way to do this in a past post: http://stackoverflow.com/questions/7024952/ninject-dynamically-specifying-a-connection-string-based-on-a-sub-domain – dehart May 15 '12 at 21:29

1 Answers1

0

After reading this post: Ninject - dynamically specifying a connection string based on a sub domain

I added a parameter to the constructor of the base repository object:

public DataObject( string connectionString)

and used the Ninject method WithConstructorArgument() in the binding code as follows:

k.Bind<Repository.Interface.Admin>().To<Repository.LinqToSql.Admin>().WithConstructorArgument("connectionString", context => GetConnString());
Community
  • 1
  • 1
dehart
  • 11
  • 2