开发者

Convert this Castle Windsor Installer to Ninject to register all repositories

I have this in my MVC2 app but I think I might move to Ninject as its becoming more popular and Castle Windsor seems a tad over complicated.

How would I do something like this in Ninject however?

Maybe Castle Windsor is more developed and I should stick with it.

container.Register(AllTypes.FromThisAssembly()
               .Where(type => type.Name.EndsWith("Repository"))
     开发者_如何学C          .WithService.DefaultInterface()
               .Configure(c => c.LifeStyle.PerWebRequest));                   


What you want to do can be done with the Ninjec.Convention extension.

https://github.com/ninject/ninject.extensions.conventions

http://innovatian.com/2009/09/conventions-based-binding-with-ninject-2-0-2/

http://innovatian.com/2010/02/ninject-extensions-conventions-preview/


You need to import the namespace Ninject.Extensions.Conventions from https://github.com/ninject/ninject.extensions.conventions Then:

Kernel.Bind(x => x
            .FromThisAssembly()
            .SelectAllClasses().EndingWith("Repository")
            .BindDefaultInterface());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜