I would like to wrap my context in an interface to allow for easier mocking with RhinoMocks.
//Instead of creating a concrete type I want to inject the interface
public Repository(ISessionService sessionService, IMyContext context)
{
//This gets the correct connection string dynamically based on a dropdown selection
var connectionString = CustomerConnection.GetCustomerConnection(sessionService.GetCustomerId());
//see link below
_context = new MyEntity(connectionString.ToEntityConnectionString(typeof(MyEntity)));
}
This converts an ADO.Net connection string to an EF connections string
This is custom code to extend the generated entity I get from the DB first model. It just allows me to pass a connection string instead of use the one that was created by the designer. The reason for using this is we use a model table that all our tables are based on.
public partial class MyEntity : IMyContext
{
public MyEntity(string connectionString) : base(connectionString){}
}
With Ninject I think it will look something like this:
kernel.Bind<IMyContext>().To<MyEntity>().InRequestScope().WithConstructorArgument("connectionString", connectionString);
So the issues:
problems: I get the customerId from session. The IOC is only established once.
question: How do I change the context when the Dropdownlist changes
problem: The sessionService is its own entity.
question: Is that value accessable in the IOC?
Am I coming at this problem from the wrong angle?