Help with Ninject in mvc3!

北城余情 提交于 2019-12-08 05:45:17

问题


Heres my problem. My app has several projects.

  • WEB (Controllers and views)
  • Services
  • Data (edmx and Repositories)
  • Entities (POCO)
  • Tests

So in my Web project I have the ninject configuration

[assembly: WebActivator.PreApplicationStartMethod(typeof(PublicPanama.AppStart_NinjectMVC3), "Start")]

    namespace Web{
        public static class AppStart_NinjectMVC3 {
            public static void RegisterServices(IKernel kernel) {
                //kernel.Bind<IThingRepository>().To<SqlThingRepository>();
                kernel.Bind<IContributorService>().To<ContributorService>();
            }

            public static void Start() {
                // Create Ninject DI Kernel 
                IKernel kernel = new StandardKernel();

                // Register services with our Ninject DI Container
                RegisterServices(kernel);

                // Tell ASP.NET MVC 3 to use our Ninject DI Container 
                DependencyResolver.SetResolver(new NinjectServiceLocator(kernel));
            }
        }
    }

The problem is, I also want to add

kernel.Bind<IRepository>().To<Repository>();

But my Web project does not have a reference to the Data project.. and just adding the reference for this doesnt seem right..

what am I missing? please help!


回答1:


http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/

And dont forget to read @Brad Wilson's blog series (ref'd in article)



来源:https://stackoverflow.com/questions/4939100/help-with-ninject-in-mvc3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!