Friday, January 13, 2012

Stand up Ninject on MVC against EF4

Here's the bindings I used to get it done


    /// <summary>
    
    /// Load your modules or register your 
services here
    
    /// </summary>
    
    /// <param name="kernel">The kernel.</param>
    
private static void RegisterServices(IKernel kernel)
    {
      
  kernel.Bind<string>()
        .ToMethod(f =>
#pragma warning disable 0618 //disable obsolete warning as this is the ONLY place this method should be used in the application
          
  ProjectDb.Adapter.EfExtensions.CreateConnectionString(
#pragma warning restore 0618
          "data source=databaseSource;initial 
catalog=YourDbName;integrated 
security=True;multipleactiveresultsets=True;App=EntityFramework"))
      .Named("efString");

      
kernel.Bind(typeof(Project.Shared.Behaviors.IRepository<>))
  .To<ProjectDb.Adapter.DEVEntities>()
  .InThreadScope()
        
  .WithConstructorArgument("connectionString",kernel.Get<string>("efString"));


    }

1 comment:

  1. Hey its Sayed Ibrahim Hashimi, I just accepted your pull request on github, wanted to chat with you quickly. Couldn't find your email anywhere can you send me an email: sayed.hashimi@gmail.com.

    Thanks,
    Sayed Ibrahim Hashimi

    ReplyDelete