I have for the first time installed Ninject. I am using the NinjectMvc3 version which gives you a NinjectMvc3 class in the App_Start folder via Nuget. There in the RegisterServices method I'm trying to hook up the entitty connection string I have in my web.config. Basically what I have right now is this.
var sConnection = ConfigurationManager.ConnectionStrings["dEntities"].ConnectionString;
kernel.Bind<IDataContext>().To<DataContext>().WithConstructorArgument("dEntities", new dEntities(sConnection));
This gives me the following error Exception Details: System.InvalidOperationException: This method cannot be called during the application's pre-start initialization stage.
And heres a some of the source error:
/// Initialize a new dEntities object.
/// </summary>
public dEntities(string connectionString) : base(connectionString, "dEntities")
{
this.ContextOptions.LazyLoadingEnabled = true;
What am I doing wrong?
EDIT: I may add that I am using Entity Framework and the Repository pattern. What I'm hoping to do is somehow create an instance of the entitites connection string in web.config and bind it with NinjectMvc3. Anyone have any good input on the matter?