I would like to have a simple sample NH project that you would consider best practice that people could refer to when getting started with NH?
I've been using it for a couple of months now and still struggle with the numerous ways there are to do things but not knowing which is the best approach to follow.
I think one of the best samples is sharp architecture. You can find Northwind example there.
Also you can look at Best practices on code project
uNhAddIns also contains some excellent samples.
Effectus is also interesting.
Still, I'll have to agree with Darin Dimitrov. There's no such things as "best" practices; there are many ways to do things and each one has its pros and cons.
Personally, I learned quite a bit from the WhoCanHelpMe application, which provides a nice reference implementation of the S#arp Architecture framework.
In addition to this, a wealth of information can be found on the following blogs which belong to NHibernate contributors:
Ayende
Fabio Maulo
Davy Brion
I think that really depends on what you mean by best approach. You may like watching some dimecasts screencasts on the subject, I have found them very informative. There are also loads of other topics too. Dimecasts.net
http://www.summerofnhibernate.com/ is a great screencast series on NHibernate
Code Camp Server is a nice reference for ASP.NET MVC and NHibernate
http://codecampserver.codeplex.com/
Also, read a book on the subjects. It will help you a long way.
Edit:
You seem to be looking for a general guide, to take you through some concepts of good design etc. Specifically for ASP.NET MVC, I can recommend http://jeffreypalermo.com/blog/read-all-of-asp-net-mvc-2-in-action-now-while-you-wait-for-the-printed-book/
You mention Onion architecture, the book was written by Jeffrey Palermo, who (AFAIK) invented the term.
If you'd like more sample projects (there are lots and lots) of ASP.NET MVC (with or without NH), let me know.
Related
I am hoping this doesn't get flagged as subjective since everyone's idea of "good" can be different. However, I know that you know what I mean, so, instead of flagging this question, feel free to edit the subject if you think it could be presented in a more objective manner. This is also not a duplicate of a good tutorial for .Net development with MVC, spring.net and NHibernate.
I come from WebForms and need to learn MVC. I came upon this tutorial on MSDN which has been great for understanding the basics of the MVC design pattern. However, it's just enough to teach someone the bare minimum so that they have everything they need to know to build a rudimentary ASP.NET MVC application. From what I've seen, the methods illustrated there aren't exactly what I'd put in a professional, enterprise solution which is exactly what I am about to start working on. I'd like to jump straight from the basics to advanced development, so I am interested in a tutorial/guide that has achieved popularity for being a solid resource for MVC development and best practices.
I realize that this question could have multiple answers, only one of which can be selected. However, there's still the upvote system, so answerers can still get points and the upvotes will still serve as indicators for helpful answers which is really what SE is all about.
I think a good starting point, it would be to check the www.asp.net site. it's certainly a good place to start. There would you find many tutorials for your purpose.
Furthermore, if you are about to buy a book, check PRO ASP.NET MVC 4 by Adam Freeman, http://www.amazon.com/Pro-ASP-NET-MVC-Adam-Freeman/dp/1430242361/ref=sr_1_1?ie=UTF8&qid=1387461608&sr=8-1&keywords=Pro+ASP.NET+MVC.
It's really a masterpiece.
It's been a while since I've looked at it, but NerdDinner helped me out when I was getting started -
http://nerddinner.codeplex.com/
http://nerddinner.com/
I'd like to jump straight from the basics to advanced development, so I am interested in a tutorial/guide that has achieved popularity for being a solid resource for MVC development and best practices.
In my opinion, using a framework in enterprise level requires deep knowledge of every part of it. why a component/class is designed, what is the purpose of it, how do we use it, what's the best practice, etc.
In this way I have found the Programming Microsoft ASP.NET MVC by Dino Esposito very helpful. The book's aim is to explain the mechanics of the framework and effective ways to use it.
I have spent a lot of time searching for best practices for designing a ASP.NET MVC 3 web site using EF 4.1 or another ORM. I found this tutorial on Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application . It was a good tutorial and I learned something. So this got me thinking and wanted to know from the people on stack is this something you would use? if not why and how did you design your web site? I just want to learn the correct way to do things and understand why one way is better then the other.
First to say Entity Framework implements a Repository pattern and a Unit of Work Pattern. Implementing Repository and Unit of Work patterns on top of a modern ORM like Entity framework is an additional layer of abstraction that:
narrows the possibilities of the underlying ORM
does not provide additional value to the underlying ORM
is at best worthless but may be harmful
One purpose of such implementations is to encapsulate the query logic in the Repository and not one query like Single Responsibility Principle (SRP) would suggest, but a couple of queries and thus violating SRP. What you could do is to rely on your ORM and encapsulate extensive query logic in single Query classes.
My suggestion is not to please "best practices" by adding abstraction layers on abstraction layers and so on but to try to solve a problem using some more general design guidelines such as SOLID.
Ayende Rahien reviews the Northwind Starter Kit application in a series of blog posts (here, here, here, here, here, here, here and here) in his blog that deal with so called best practices applied in an application. This is a great read!
I've been seeing a lot of articles and references about how to use this patterns for my first (please keep this in mind) serious project with ASP.NET MVC 3 and EF.
The project is not so big (13 tables) and it's basically a CRUD maintenance: organisations that have some users; users that can belong to a group and can create some work areas and templates... Nothing complicated. The point is that this will be the first of a project series and I'd like to create a base to work with.
My questions are:
Which of the previous patterns is the best? Does it depend of the project size?
My models would be these:
Unit of work
Dependency Injection
Do you think they are good enough and appropriate for my project?
I appreciate all your comments.
Serious application doesn't mean to be complex at first sight.
Over engineering an application upfront can be a real disaster, especially if you don't grasp all the technologies involved.
My advice would be to keep it simple. Create a basic application that fulfill requirements (get the thing done and make your boss happy) and then add new concepts along your learning path.
That doesn't mean I promote bad code, no way! Keep your code clean, well organized, etc. But don't be killed by the fear of doing something wrong.
It's normal for a developer to look back to an application made a few weeks ago and then realize that he did some shitty stuff. That's how we progress!
Last but not least, have FUN!
ASP.NET website provides usefull resources to learn the framework and all related guidances. There are a few application samples created step-by-step.
ASP.NET MVC was built with Dependency Injection in mind.
If you want to give a chance to your code to be loosely coupled and easier to change in the future you have to follow the patterns like Dependency Injection, Repository (for presistance abstraction), and UoW (for transaction abstraction).
So my answer is, you should learn about them in the first place to decide after if you want or no to follow the best practices. Even for simple project it's good to apply these patterns because often it gets bigger and bigger. and it's easy to do it in MVC so why to avoid it ?
There is many resources around to learn about. You can just google it.
I would like to answer this question in more generic way. Creating something which can be used in future is difficult than what it seems. All the pattern above can provide you infrastructure pieces to come up with some base framework.
But I would strongly suggest you to look at S.O.L.I.D principals (DI being part of it) to understand some qualities of good code. These are applicable irrespective of the technology involved.
You cannot predict the future requirement of a product\framework, but following these principle you can be better prepare to handle any future modification to the software
You might want to check out S#arp Lite which has many good examples of how to implement the things you want and can serve as a very good base on which to build something quickly.
None of the mentioned patterns are mutually exclusive. You should use the patterns that make sense based on what you are trying to accomplish, not attempt to shoehorn your application design into someone elses idea of how it should work. Sometimes trying to bend your scenario to fit a particular design pattern / practice is the worst thing you can do.
Want to make sure good unit test coverage / do TDD / ensure loose coupling? Then Dependency injection is your friend, as is the Unit of Work pattern. This is definitely a good idea for creating a maintainable, scalable application, but you can go too far with it for a small-scale application.
Need a centralized caching strategy for your data source? Then use the repository pattern. Or an ORM like NHibernate, which might do it for you.
I’m new to asp.net and the mvc framework and I’m trying to learn by using the asp.net learn tutorials for Building a Contact Management Application in vb (http://www.asp.net/learn/mvc/tutorial-29-vb.aspx).
The question I have is that I would like to begin a new project to start using mvc, but how do I start….
The tutorials start by putting data access and logic into controllers at first and then making the application loosely coupled by refactoring the code.
Is this the way to approach a new project or should I be making the application loosely coupled from the start?
I have followed the next iterations of the tutorials about TDD but couldn’t get my head around that just yet and wanted to really focus on cementing what I’ve picked up so far.
Any help or advice would be great.
I would probably check out the NerdDinner sample app and eBook. It provides some pretty good direction on the best way to do things. Link Here
Id recommend jumping straight into the sharp architecture stuff.
http://www.sharparchitecture.net/
Rob Conery has a good series of walkthroughs in regards to creating an asp.net mvc storefront application. I think they include TD stuff, but are done in C#. Here is the link.
I don't mean to scare you but I wasn't really productive until my 4th project.
Sure, I managed to hack out a few sites but if anyone looked at the code I wouldn't own up to it! :)
Nerd Dinner is certainly the place to start. I also found this site to be one of the most useful.
The trick I found was to, once Nerd Dinner was out the way, pick a pet project and get into it. Then, I picked another pet project and corrected the mistakes I made in the previous one. The 4th project actually resembled a well written site.
It's just because the paradigm for writing sites in mvc is so different that there is a pretty big learning curve. At least that's been our experiance here.
I also recommend S#arp all the time. I was novice to IoC, NHibernate, and MVC when I started, and S#arp was a big help. As for VB, S#arp can be used as binary assemblies; however this surely won't be as easy.
For VB/C# look here: https://stackoverflow.com/questions/1653895/should-i-learn-vb-net-or-c. I personally rarely answer VB questions, and I find C# lambda very helpful, so I can confirm many points there.
But if you only need to learn MVC, not to start real project, NerdDinner will do. Just don't take it as real-world best practices; it's to teach MVC stuff/features, not how to write well-designed and maintenable programs.
I'd like to build a CMS site based on Asp.Net Mvc and I want to choose my starting point.
I have seen that there is a lot of interest in the new Microsoft Oxite project also if it seems to be pretty early to adopt it in a production project.
I've also looked at S#arp Architecture but it does not properly compare to Oxite as is just a starting point for general Asp.Net Mvc sites.
For me S#arp Architecture has some advantages over Oxite as is far less complex and it uses Nhibernate for the data access layer.
Oxite code uses Linq2Sql for it's DAL and has already a project in the solution that requires the DB version for VS2008.
Oxite seems to me more blog oriented than CMS oriented but I haven’t looked the code deeply.
Here are some of the choices that would point me to S#arp Ar. for starting.
Simple clean architecture
Nhibernate Dal
Community supported
Oxite:
Microsoft project
Potential huge community
Early stages but very good code quality
Provider model that permits to easily switch the DAL
If anyone has looked at the code of these two projects please advice on your opinions.
Thanks
Oxite might be feature rich, but the code quality is very low.
I was very surprised when I checkout the code and found controller actions with 100+ lines of very unclean code, tagsoup views, no unit tests, etc.
The criticism has been well summed up in these blog posts:
http://blog.wekeroad.com/blog/some-thoughts-on-oxite/
http://codebetter.com/blogs/karlseguin/archive/2008/12/15/oxite-oh-dear-lord-why.aspx
As always, it depends on your needs. It sounds like you need something more CMS based. Oxite happens to have some CMS-like features, but it's not really a CMS. It might be in the future as it's a community project, but right now it isn't (all you can do is add content pages).
We're glad everyone seems to like Oxite overall, but it is pretty early. Not to deter anyone from using it in production, because we do. We run MIX Online on it, but totally understand if you're not comfortable with it. We need a stabilization period. At the same time we also need people running it so we can make it stable. Chicken and Egg I'd say. :)
I didn't get much of a response at my question about Oxite here at SO (found at Oxite: What are you going to do with it?), but it is really new so it'll take some time for people to warm up to it and fully check it out. The architecture of Oxite is really easy to get started with; that's its strongest suit.
I'd never heard of S#arp before I read your question so I'll definitely check it out.
Oxite is well detailed already, entirely negatively.
I'll just add that I've been using S#arp architecture for several months and found it very maintainable and flexible. There's also a very solid, growing and active community of users around it.
It is very clean, and quite easily upgraded to Fluent NHibernate RC 1.0