Results 1 to 16 of 16

Thread: [RESOLVED] MVC and IoC

  1. #1

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Resolved [RESOLVED] MVC and IoC

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MVC and IoC

    Quote Originally Posted by gep13 View Post
    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.
    Quote Originally Posted by gep13 View Post
    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).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: MVC and IoC

    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. Good stuff


  4. #4

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC and IoC

    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

    Gary

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MVC and IoC

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC and IoC

    Quote Originally Posted by jmcilhinney View Post
    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

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MVC and IoC

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC and IoC

    Hello,

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

    Gary

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MVC and IoC

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC and IoC

    Ok, I will have a dig around, and see what I can find.

    Thanks

    Gary

  11. #11

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: MVC and IoC

    Quote Originally Posted by gep13 View Post
    Hello,

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

    http://www.asp.net/mvc/tutorials/val...rvice-layer-cs

    http://www.asp.net/mvc/tutorials/ite...ely-coupled-cs

    Thanks!

    Gary
    Indeed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: MVC and IoC

    Quote Originally Posted by jmcilhinney View Post
    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

  14. #14
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: [RESOLVED] MVC and IoC

    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 (Works with beta 1 but I believe anything that has changed has been noted.)

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

  15. #15
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: [RESOLVED] MVC and IoC

    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
    - Video and Code aren't posted yet (7:15 PST) but I'd expect them to be up in the next couple of hours.

  16. #16

    Thread Starter
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] MVC and IoC

    Hello there,

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

    Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width