How do you use Presentation Model with Webforms? - asp.net

I have started using Presentation Model w/ ASP.NET webforms and like the pattern quite a bit. What I am really having an issue with is where to instantiate some of my classes, mostly the presentation model, my business object, and things like the data for drop down lists. So I could use some tips or a complete example of the Presentation Model (I have only find pieces so far).

Video Links -
Rik Bardof on Design Patterns (including MVP)
Jean Paul Boohdoo on MVP
As far as the rest of your architecture goes, I would recommend reading Jeffrey Palermo's blog series on Onion Architecture. He has a sample project CodeCampServer that illustrates some good practices. This is a web app using ASP.NET MVC, but the principles still apply.

Related

asp.net pattern - domain model

I am reading professional asp.net design patterns by Scott Millet.
And I am on page 68 - reading Domain Model.
I really like the way Domain Model works. But I need simpler example to show me how it works.
Do you know any resources I can read? or even have a lab I can try and move on?
I don't need something with MVC because I am not there yet. And my domain model
will work with different platform.
You say that you don't need MVC because you are "not there yet". My opinion, based on my own experience, is that a great way to build your skills would be to dual track on intro MVC while doing more reading on DDD. Jimmy Nilsson's book, "Applying Domain-Driven Design and Patterns" is famous and comprehensive but also very approachable. I would read that and, at the same time, step through the 29 videos at: http://www.asp.net/mvc/videos/mvc-2/how-do-i/creating-a-tasklist-application-with-aspnet-mvc.
Also, you'll notice that Scott Millet thanks Rob Conery in the acknowledgements to the book. I think you might be helped by some of Rob's free videos at TekPub. In particular, I'm thinking of the free five part series called "Concepts" [http://tekpub.com/products/concepts] that covers DI, IoC, "Loose Design with Interfaces", "Behavior-driven Design with Specflow", and more.

ASP.NET MVC3 Design Patterns and Proper Coding techniques

I recently worked at HP doing several ASP.NET MVC3 projects as I came from a software background I was relatively new to the inner workings of MVC3 as well as the best practices.
During this time I somewhat adapted the coding style of fellow co-workers and ways of designing my pages that I still stick with to this day. With all of this in mind my main question is what would anyone recommend for learning material; books/videos/tutorials. I can learn from any of those resources and I would love to know that I am coding properly.
I have several projects under my belt and many large scale business solutions that I have coded using Razor and ASP.NET but there are times where I feel that what I am doing is either very hacky or just an inefficient way of coding things. The larger the project is the more difficult it becomes to add new features because of this.
I think this is my lack of experience in coding but at the same time I would like to overcome this and I feel that with the mass experience I do have with MVC3 I could adapt to a easier style or design pattern that would help me not only optimize my code but become a much better web developer. If anyone has any suggestions on books or training sites or anything please let me know as I would love to get better.
Thanks in advance to anyone that has been in my shoes and is willing or capable of recommending anything!
I was dealing with the same issue and found it useful to make a mind map. While it's impossible to give you a full understanding, I can try point you in the right direction with some basic ideas.
download/view (http://www.xmind.net/share/highroad/mvc3-design-pattern/)
Are you familiar with design patterns? Well they exists with MVC applications too :)
If you want to talk the talk and understand what people including myself are talking about, you would need to know the typical design patterns that come with building what they call enterprise level applications. These design patterns are the only real way to begin to understand the concepts.
These patterns structure complex business logic in ways that have become the tried and tested solutions (design patterns) to the design challenges the developer's face.
In the diagram notice there are 3 main layers:
Presentation Layer
Business Logic Layer
Data Access Layer
Some of the highly used design patterns when dealing with Model View Controller in ASP.NET include:
Business Logic Layer Design Patterns:
Active Record. Models relate exactly to the database like in lightweight frameworks e.g. Ruby on Rails). When creating new MVC3 application with ASP.NET and scaffolding views and controllers, this is how it sets it up. Is perfect for less complex applications. So why not just use Ruby on Rails? I would
Domain Logic Layer. Uses MVC with the controller containing very little code and create lots of extra models that can do complex logic, the MVC is only for presentation. Often with this style of layer, a lightweight layer called a Service Layer can be used to call all the functions in the Domain Layer from the controllers i.e. the controller calls the method in the Service Layer class which calls the domain layer. This design pattern seems to be very popular with people who enjoy object oriented programming. See link below to my (quite basic) project designed using Domain layer.
Transaction Script - Use the controller to do a lot of the logic work per action, the problem is a lot of actions need to do the same things so there will be code repetition
For the Data Access Layer:
Something like entity framework models combined with a repository which can perform any SQL queries you need.
Not going into all the patterns for this layer but they include: Data Mapper
With simple apps, there is no real data access layer, it only becomes necessary if you use the Domain Layer in the business layer (which usually is the case)
Depending on what structure your application takes, your Models will mean very different things. In general they will not be models linked to the database (the default when creating a new app makes them like this). Instead they will be ViewModels which are only responsible for holding data that each of the views will need.
I have created a ssample app which you can see here.
https://github.com/testbrian/enterpriseframeworksB
I don't know if this is an example of an enterprise solution, but I have learned a lot from the techniques found in RaccoonBlog. I like how the Layout.cshtml and other razor files use RenderAction to modularize the views.
The project is an example of MVC3 using RavenDb, but it's also one of the best real world applications I've seen since it's actually used in production.
Hope this helps.

to learn entity framework, how do i use it in a pet project?

i want to learn entity framework. i started with some EF tutorials and i also know little about linq to sql.
i want to learn through a pet project. project should be in three layers. web forms (prez), data layer(c# lib), bussiness layer(c# lib). Project can be any, any functionality. just want to learn how to use EF in diff. layers and in UI.
can anyone guide me how do i start to do layering? help me to learn how should i use EF objects from DAL layer to BL and then UI.
I am confused as all tutorials shows direct binding of EF to EF datasource in UI and with controls.
thanks a lot.
In order to maintain a layered architecture I would create partial classes of the generated EF Classes. In these classes I would have methods I could use with objectdatasources in the presentation layer. Thats how I do it anyways, hope it helps!
A couple of things I would recommend:
Rob Conery (with occasional guests) put together a video series on building a storefront site using ASP.NET MVC. He used LINQ-to-SQL, not Entity Framework, but I don't think the difference is significant to what you are interested in learning. One nice thing about this series is that he walks you through the various design decisions he makes, and even backtracks when he later feels that one of them was wrong. Another is that, in addition to MVC and LINQ-to-SQL, he also explores some other development concepts such as inversion of control and test-driven development.
Martin Fowler's book Patterns of Enterprise Application Architecture is a great resource for this sort of thing. He lays out the different patterns that are available in each tier of your application and discusses how to use them and when each is appropriate. Fowler's writing style is friendly and easy to read, and a lot of the patterns in his book are prominent in the vernacular of the software development world today (e.g. Repository pattern, Active Record, Unit of Work).
Hope this helps!

is it possible to use MVP pattern with Codesmith Ntier or PLINQO Template

Currently we are working on ASP .net application and i would prefer to go ahead with MVP pattern (for UI) due to several advantage it provides,
But the con of going ahead with that approach is too much of hand coding which will eat up time.
I already identified that it is possible to generate DAL with any template or by using LINQ to SQL but the only issue is with generating interface which should be implemented by usercontrol (view) and some boilerplate code (for data binding)
Now the question is
1) Is it possible to use codesmith template to get the MVP pattern (To generate interface & properties at UI layer as well as data binding)
2) It is not advisable to go ahead with MVP pattern and use the simple approach provided by codesmith template generator or any other tool
Note : I have also considered to go ahead with ASP .Net MVC but due to lack of knowledge (learning requirement) and project time line we have to drop that idea.
EDIT : In terms of man month effort it is of around 35-40 man month's effort to develop this application
Please suggest me.
1) Absolutely possible. The "how" depends quite a lot on what specifically you are doing and how well templates fit your patterns (or how well your needs can be distilled to code generation in general).
2) Impossible to say. Depends entirely on your needs.
You should really investigate ADO.NET Data Services and ASP.NET Dynamic Data Scaffolding frameworks. These are designed exactly to do the kind of generation you are asking for.
A bit late but checkout the codesmith templates I just released.
http://community.codesmithtools.com/CodeSmith/m/templates/42499.aspx

Resources for implementing MVVM (ViewModel) pattern in Flex?

Can anyone direct me towards some code or a tutorial for implementing the ViewModel in Flex 3?
All I'm finding on the web are examples for Silverlight.
Martin Fowler has also written about these ideas in the past under the term "Presentation Model". So you might find useful tutorials under that search phrase as well since it's not an "MS invented term". :-)
Indeed, this MS overview material acknowledges Fowler's work directly
In 2005, John Gossman, currently one
of the WPF and Silverlight Architects
at Microsoft, unveiled the
Model-View-ViewModel (MVVM) pattern on
his blog. MVVM is identical to
Fowler's Presentation Model, in that
both patterns feature an abstraction
of a View, which contains a View's
state and behavior. Fowler introduced
Presentation Model as a means of
creating a UI platform-independent
abstraction of a View, whereas Gossman
introduced MVVM as a standardized way
to leverage core features of WPF to
simplify the creation of user
interfaces. In that sense, I consider
MVVM to be a specialization of the
more general PM pattern, tailor-made
for the WPF and Silverlight platforms.
I wanted to share a comparison I wrote up of MVVM (Silverlight) vs PresentionModel (Flex). It shows how the two implementations of the same pattern differ/compare:
http://houseofbilz.com/archives/2010/12/29/cross-training-in-silverlight-flexmvvm-vs-presentation-model/
The reason all of the examples your finding are for Silverlight is because MVVM is by-and-large a Microsoft invention. It has to do with the ease of tying WPF views with data. The "ViewModel" is little more than a way of describing a subset of functions performed by the Controller in a traditional MVC design model; some MVVM descriptions even include a controller.
With that said, it doesn't really matter whether your app follows the MVVM or MVC models precisely. It's more of a high-level, organizational idea that should guide your design and development. If you're totally clueless about the models you can find any number of quickie web tutorials, and probably some printed literature on the subject.

Resources