ASP.NET MVC + fluent nNibernate, what IoC tool?

2019-02-06 21:05发布

I'm working on a ASP.NET MVC project where we have decided to use Fluent nHibernate for dataccess. To enable loose coupling we go for a IoC/DI pattern. My questions is what IoC tool to go for. I've tried to find the differences between windsor, ninject, spring, structuremap and unity, but it's difficult to see the benefits each one has to offer. Whats your experience?

5条回答
孤傲高冷的网名
2楼-- · 2019-02-06 21:43

I have been using Windsor and love it. There is a built in facility for using NHibernate which allows for simple configuration of logging and connections etc.

If you plan to use FluentNhibernate you have to tell the Windsor facility which assembly has the ConfigurationBuilder. Mike Hadlow has a great write up on this plus many others on Windsor and NHibernate: http://mikehadlow.blogspot.com/2009/01/integrating-fluent-nhibernate-and.html

查看更多
家丑人穷心不美
3楼-- · 2019-02-06 21:49

I use Munq which is lightweight and fast and is a simple way to add a DI Container to MVC3 projects via Nuget. Up to now I haven't found any need to move to a different framework - Munq has been very adequate.

PM> install-package Munq.MVC3

This adds App_Start\MunqMvc3Startup.cs to the project, and this is where dependencies should be registered.

查看更多
做个烂人
4楼-- · 2019-02-06 21:55

I use Windsor and I've nothing to complain about. Easy to use, extensible when you need it and a lot of information if you get stuck. But I don't think it matters that much which container you choose. All of them you mention have the common features and there're also adapters for mvc availiable in the mvccontrib project. A switch to another container shouldn't be difficult if you wrap the container in an own class, which is a good practise anyway.

查看更多
叼着烟拽天下
5楼-- · 2019-02-06 21:58

I use StructureMap and it's very easy to use. Personally I don't like to configure using xml and StructureMap makes it a breeze to configure using code. It's also very easy to switch different profile if you need to switch implementations.

查看更多
一纸荒年 Trace。
6楼-- · 2019-02-06 22:03

Scott Hanselman has a pretty good compare/contrast article on a lot of the popular .NET IoCs:

http://www.hanselman.com/blog/ListOfNETDependencyInjectionContainersIOC.aspx

查看更多
登录 后发表回答