PDA

Click to See Complete Forum and Search --> : [RESOLVED] MVC and IoC


gep13
Mar 19th, 2011, 08:47 AM
Hello,

I have still not as yet attempted a complete ASP.Net MVC Project, but I am toying with the idea of recreating my own website using ASP.Net MVC. I have been reading a lot lately about Inversion of Control (IoC) and Dependency Injection (DI), and I was looking for recommendations about which technologies I should use.

Do anyone of you use IoC and DI with your ASP.Net MVC applications?

Also, MVC obviously give you the separation of concerns for the UI perspecitive, but what techniques do you use for separation of concerns with regard to the Database, i.e the traditional BLL and DAL. How are those implemented in an MVC application?

Thanks in advance!

Gary

jmcilhinney
Mar 20th, 2011, 08:10 PM
Do anyone of you use IoC and DI with your ASP.Net MVC applications?I'm currently using Castle Windsor in one project because it's part of the client's own application development framework. We're also using Autofac in a WPF MVVM project. I'm planning on looking at others in my spare time too, when I get some. Those two seem OK but I don't have to much to compare with at this point.Also, MVC obviously give you the separation of concerns for the UI perspecitive, but what techniques do you use for separation of concerns with regard to the Database, i.e the traditional BLL and DAL. How are those implemented in an MVC application?Service layer, repository, data transfer objects (DTOs).

Krokonoster
Mar 21st, 2011, 12:30 AM
While I eventualy moved to StructureMap (had to for work) I used to use Castle also.
Back then this kid got me going with his articles (http://www.dominicpettifer.co.uk/Blog/38/dependency-injection-in-asp-net-mvc-2---part-1--controllers). Good stuff

gep13
Mar 21st, 2011, 02:42 AM
Hello there,

Castle Windsor is the one that I keep hearing about, so I think I will run with this one to start with. It just feels like there is SO much new technology out there just now, that it is difficult to know where to start.

John, are you using Entity Framework at all at the back end, or do you find that you don't need it?

Krok, thanks for the link, I have bookmarked it :thumb:

Gary

jmcilhinney
Mar 21st, 2011, 03:30 AM
We're not using EF in either of the two projects I mentioned earlier because the client framework for the MVC project requires NHibernate and the MVVM project uses Oracle, for which there was no final EF provider available (and may still not be). The IoC container doesn't really affect the choice of data access technology anyway though.

gep13
Mar 21st, 2011, 04:58 AM
The IoC container doesn't really affect the choice of data access technology anyway though.

Oh yeah, totally agree. I guess my original question was actually two questions :)

Typically, I have always had a DAL that talks to the SQL Database directly, and then a BLL to interface with the DAL, and so on. Having never played with EF, I can't picture in my head, how to separate the concerns once you have the DataContext model created.

(I realise this is getting off topic :))

Gary

jmcilhinney
Mar 21st, 2011, 06:12 AM
Your EF data model or L2S data context or whatever is encapsulated in the repository. The demo project on the ASP.NET does just that.

gep13
Mar 21st, 2011, 06:38 AM
Hello,

Can you clarify which demo project you are referring to? Thanks.

Gary

jmcilhinney
Mar 21st, 2011, 06:50 AM
Hmmm... looks like the MVC 3 tutorial doesn't demonstrate implementing a service layer and repository, where the old MVC 1 & 2 tutorials did. I'm sure that you would be able to find examples though.

gep13
Mar 21st, 2011, 08:31 AM
Ok, I will have a dig around, and see what I can find.

Thanks

Gary

gep13
Mar 28th, 2011, 08:40 AM
Hello,

John, to confirm, are these examples of what you were referring to:

http://www.asp.net/mvc/tutorials/validating-with-a-service-layer-cs

http://www.asp.net/mvc/tutorials/iteration-4-make-the-application-loosely-coupled-cs

Thanks!

Gary

jmcilhinney
Mar 28th, 2011, 05:55 PM
Hello,

John, to confirm, are these examples of what you were referring to:

http://www.asp.net/mvc/tutorials/validating-with-a-service-layer-cs

http://www.asp.net/mvc/tutorials/iteration-4-make-the-application-loosely-coupled-cs

Thanks!

Gary

Indeed.

gep13
Mar 29th, 2011, 01:34 AM
Indeed.

Noice! Thank you very much.

I have added this to my growing list of things to read up on. Thanks for your help!

Gary

MattP
Apr 14th, 2011, 09:14 AM
Thought I'd throw a couple other options out there for containers. I prefer Unity myself and a lot of the examples I see out there use MEF.

ASP.NET MVC 3 Service Location (http://bradwilson.typepad.com/blog/2010/07/service-location-pt1-introduction.html) (Works with beta 1 but I believe anything that has changed has been noted.)

http://forums.asp.net/1146.aspx - Official MVC forums

MattP
Apr 15th, 2011, 09:15 AM
They had a session on using MVC 3 and MEF at MIX 11 yesterday. Should be beneficial even if you're using a different container.

Fun with ASP.NET MVC 3 and MEF
(http://channel9.msdn.com/Events/MIX/MIX11/OPN07) - Video and Code aren't posted yet (7:15 PST) but I'd expect them to be up in the next couple of hours.

gep13
Apr 15th, 2011, 04:04 PM
Hello there,

Thanks for the heads up, will be sure to take a look at that!

Gary