Subscribe: Chris Stewart's ASP.NET Blog
http://weblogs.asp.net/cstewart/rss.aspx
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
book  data  dependency injection  dependency  framework  injection  linq  mvc  net mvc  net  new  project  session  web 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Chris Stewart's ASP.NET Blog

Chris Stewart's ASP.NET Blog



My experiences with ASP.NET



 



My "Ah-Ha!" Moment With LINQ

Fri, 14 May 2010 01:06:00 GMT

I'm currently working on a set of web services that will be consumed by iPhone and Android devices. Given how often the web services will be called in a relatively short period of time, the data access for the web services has proven to be a very important aspect of the project. In choosing the technology stack for implementation, I opted for LINQ to SQL as it was something I had dabbled with in the past and wanted to learn more about in a real environment. The query optimization happening behind the scenes was something that I had an appreciation for.

Once I completed the implementation of the web services we noticed a performance bottleneck on one of the calls. LINQ to SQL was doing all it could to help us in this situation but the nature of the required response was simply too heavy on the database to expect any real performance from any query. We ended up being able to cache the data we were querying against which would help tremendously.

What I was expecting was a large re-write of code to accommodate my new source of data. Instead, using LINQ, I was able to simply change the from statement in my LINQ query and get the results I needed. Essentially, when building the cache, I create a List collection for the objects I'll need to query against and subsequently return to the mobile device. The results of that general query are stored in cache. When I need to perform a query against that cached collection, I have a LINQ query, which I used previously to query the database tables, that now uses the cached collection as it's data source. Which is really a fancy way of saying the "from" statement in the LINQ query. There were no ugly nested loops with various comparison statements needed.

Going from querying a database to querying a local in-memory collection was beyond trivial with LINQ. After getting it up and working, I fell back into my chair in amazement.



Book Review: ASP.NET MVC in Action

Mon, 13 Jul 2009 00:41:00 GMT

I've had the pleasure of being able to review ASP.NET MVC in Action in it's early access form.  If you've not heard of this program, Manning has a program called MEAP (Manning Early Access Program) which allows you to purchase the book before it's published and gain access to it in PDF form as the author makes the chapters available.  In this case, I've been reading parts of the book nearly a year before it will be physically published in Sept 2009.  I highly recommend checking that out, as I've participated a number of times.  In fact, I purchased C# in Depth, 2nd edition over the weekend in MEAP.  I have access to the 1st edition via PDF, access to the 2nd edition in PDF, and will receive a hard copy when the 2nd edition is published.  An excellent way to receive books in my opinion.  Anyway, on to my review of ASP.NET MVC in Action.

Being a book on a new technology, it's a given that the author took the time to discuss the details of the framework.  Every major difference between ASP.NET and ASP.NET MVC is covered in detail.  The author presents the fundamentals of the framework in a very easy to understand format.  If you've never heard of the MVC pattern, you'll find comfort in this book.  In fact, the pattern is even discussed outside of the Microsoft .NET implementation.  These are common expectations with a book on new technology, and the author was able to deliver on all of them.

What makes this book standout to me, is the CodeCampServer project mentioned throughout this book.  The author created this open source project, using ASP.NET MVC and a host of best practices.  I had actually been following the project before I knew the book was being written.  Being able to read about the technology, then quickly download the source for the CodeCampServer project to see it in a real-world application, is a real treat.  It's rare to find a book that extends beyond the text, that provides a real application you can use to understand the points outside of the text.  How do I structure my ASP.NET MVC project in the real-world, outside of a book sample?  How does TDD apply to ASP.NET MVC?  How does Dependency Injection fit in the ASP.NET MVC framework?  These are real questions that you'll ask yourself, that most books wouldn't touch.  With this book and the CodeCampServer project, you'll find answers to those questions.

I'm very happy with this book.  I would definitely recommend it to anyone interested in ASP.NET MVC.  Getting the "beyond the text" that comes with the CodeCampServer is just icing on the cake, truly.

 




"A Beginner’s Guide: ASP.NET 3.5" Is Here!

Wed, 24 Sep 2008 23:31:00 GMT

Earlier this year I had the opportunity to be the technical editor for McGraw-Hill's A Beginner's Guide: ASP.NET 3.5.  After many months of waiting, the final copy hit my doorstep this morning!  It's great to see something you worked on in final printed form.  It was almost surreal to see my name and bio inside the front cover.

The author, William B. Sanders, did an excellent job with the title and I can't wait to read through it again.  Of course, I highly recommend it for anyone that needs an introduction to ASP.NET 3.5.

http://www.infibeam.com/Books/info/William-Sanders/ASP-Net-3-5-A-Beginner-s/007159194X.html



Book Review: Programming .NET 3.5 by O’Reilly

Thu, 11 Sep 2008 13:14:00 GMT

I just finished reading a review copy of “Programming .NET 3.5” from O’Reilly. The book, published in August, is an overview of the latest .NET Framework revision. You’ll get an introduction to the topics that have been introduced along the way that include technology from .NET 2.0, .NET 3.0, and the latest version; .NET 3.5. Also included are libraries such as ASP.NET MVC and Silverlight.

You can easily pick up this book and enjoy the introductions to technologies such as Windows Communication Foundation, Windows Workflow Foundation, Windows Presentation Foundation, ASP.NET MVC, and Silverlight. Each of these topics are presented in a way that will be familiar to .NET developers. New developers, without experience in .NET, will be able to take a lot away from this book. It certainly will do more for the developer who already has a .NET background, no matter how brief it is.

That said, if you only pick up the book for the introduction to each technology, you’ll be missing the best that this book has to offer. Unlike most technology books these days, this book explains the topics within the context of best practices and real world scenarios. For example, prior versions of ASP.NET did not promote decoupled architectures. In fact, it made it difficult to achieve them. With the technology available in .NET 3.5, modeling and implementing proper architectures is encouraged and facilitated by the framework. This book will show you how that works in .NET 3.5 and introduce you to the technologies at the same time.

I highly recommend this book. It will be on my desk for easy reference for my .NET projects in the future.




Book Reviews Coming!

Wed, 03 Sep 2008 16:17:00 GMT

It's been way too long since I've posted here.  Yes, I'm still around, and I'll be posting some topics very soon.  I've been lucky to receive some great books related to .NET and I'll be posting reviews of each of them shortly.

At work, I've been primarily working in the J2EE world.  I've enjoyed most of it but man, I really miss .NET.  It sounds stupid but I really enjoy the experience of developing with Visual Studio and the .NET platform.

Stay tuned!




Technical Editor for .NET Books

Mon, 05 May 2008 20:24:00 GMT

I've had the pleasure over the last few months to perform technical editing for McGraw-Hill on an upcoming ASP.NET 3.5 book aimed towards beginners. This has been my first experience being a part of the process of putting together a book. I really enjoyed doing this kind of work and working with the author in his efforts to bring forth a great book for beginners to learn about ASP.NET, specifically 3.5 material. You can find the pre-order page here on Amazon (http://www.amazon.com/ASP-NET-3-5-Beginners-William-Sanders/dp/007159194X).

Today I was given the opportunity to act as the technical editor for another project for McGraw-Hill. I'm definitely looking forward to this book and working with the author. This book will likely publish at the end of this year. Of course I'll give more details once that date approaches.

I'm very interested in continuing to perform technical editing for publishing companies. In the future, I'd really enjoy the opportunity to author my own book. Until then, I'll stick with the editing gigs. If you'd like to hire me as a technical editor, please contact me at cstewart913 [AT] gmail.com.



iPhone SDK Development

Fri, 04 Apr 2008 00:13:00 GMT

I know it's unrelated to .NET but I'm a Mac person, so I've been really drawn in to the iPhone SDK. Am I the only one from the Microsoft developer community? I've even started up a blog and forum dedicated to the topic: http://www.iphonedevsdk.com



Book Review: LINQ Quickly

Fri, 28 Mar 2008 13:11:40 GMT

I've been reading another book from Packt Publishing, called "LINQ Quickly".  Again, it's a pretty short book, coming in at 250 pages.  The author does a decent job at explaining the basis of LINQ and the various implementations, such as LINQ to SQL, and so on.  What would have been a welcome addition to this book is a more practical approach to the technology.  Perhaps by building a real application along the way.  There is an appendix for just that, but it's a disappointing 7 pages.  The book's subtitle mentions it being a practical guide but I didn't see that.

If you want a brief overview of what's possible with LINQ and the various implementations, you'll probably find the same information for free across the web.  I was hoping for more of a real-world introduction.




Book Review: ASP.NET 3.5 Unleashed

Mon, 25 Feb 2008 16:28:38 GMT

I've been working my way through "ASP.NET 3.5 Unleashed" lately.  Although I'm not quite finished, since the book comes in just under 2000 pages, I do feel confident in writing a review.

The Unleashed series has a certain following behind it for being a fairly comprehensive guide to the technology the book examines.  This entry into the series is no exception.  This book goes into every detail of ASP.NET and ready digs into the new features of 3.5, as you may expect given the title.

I've enjoyed the way this book presents material.  It's not too detailed for the beginner but doesn't leave the experienced wanting too much more.  I would highly recommend this book to anyone looking for information on ASP.NET 3.5.  This book is something every ASP.NET book should aspire to be.




Dependency Injection was made for ASP.NET MVC

Tue, 12 Feb 2008 15:01:00 GMT

It's not that you can't use dependency injection in any .NET application, because you can.  It's just that dependency injection fits so well in the ASP.NET MVC programming model.  While building up a simple example for how my new application would be architecturally designed, I found using dependency injection with Web Forms as troublesome as trying to fit a square peg into a round hole.  After some modifications and adjustments, I could get it to work, but it just didn't feel like a solid fit and certainly didn't make me any more productive.

I decided to give the ASP.NET MVC programming model a try and found the experience much smoother.  Not only did everything simply work easier, but you get a sense that the two were meant to be used together.  Using the Controller approach found in MVC, it's extremely easy to inject your dependencies using constructor injection.

Designing software while using dependency injection has changed my normal approach.  I've found myself creating an extra layer or two of abstractions.  The implementation of the classes I'm building is pretty simple and somewhat resembles the Facade pattern.  My classes essentially boil down to a small set of service classes that are injected into the Controllers as needed.  All of the services that are injected into the Controllers are done so by using interfaces for the service.  The concrete implementation of the service classes are actually composite classes.  They use the various repository classes (think subsystem) they need to offer up a set of common methods that define the service.  I guess it sounds more complicated than it really is, but the idea is that everything is loosely coupled to everything else.  Everything is interface driven, so supplying concrete implementations is the job of StructureMap, my dependency injection framework of choice.

I can't say that dependency injection is "the way to go" for every scenario.  In fact, my current application doesn't really need it except for maybe one instance.  However, what I do like about using dependency injection is the side effect I mentioned above.  Using it has me thinking about my n-tier architecture in a different way than before.  I've found useful instances of working in an interface driven environment.  I also enjoy the approach of creating services for the various subsystems in my framework.  It's certainly something you can do without dependency injection and ASP.NET MVC, but it's something I've found very useful in solving business problems while using those technologies.

(image)



StructureMap for Dependency Injection

Fri, 08 Feb 2008 18:44:53 GMT

I decided to go with StructureMap as the dependency injection framework for my next project.  I choose StructureMap for a number of reasons.

StructureMap has been around for quite some time.  Not that this makes it better than any other framework.  However, coupled with the fact that it's an active project, it's still a hot topic in the world of DI for .NET, and a lot of .NET developers use it in their applications, I feel pretty good about it's history and future.

StructureMap 2.0 does not require an XML configuration file.  In my opinion, the last thing we need as .NET developers is another XML configuration file.  That's what I dislike the most about Java.  You can't build a J2EE application without writing a mountain of XML configuration.

Probably less of a feature and more of a convenience to me, is that StructureMap has only one purpose and that's providing a dependency injection framework to .NET developers.  Spring.NET is nice and it does a ton of things.  That scattered focus left me feeling scattered after creating a sample project using Spring.NET.  I'm sure everyone has their own feeling towards this but for me, I felt less interested in Spring.NET after reading and reading about all of the various things that framework can do.  I just wanted DI and that can be done in Spring.NET rather easily and separate from everything else the framework provides.  It's just information overload while trying to learn the one specific thing I wanted to learn.

So there you have it.  I'm excited to get started on this project and dig deeper into StructureMap.  I'll certainly provide opinions and lessons learned throughout the process.




Which Dependency Injection Framework?

Thu, 07 Feb 2008 18:16:58 GMT

I'm in the planning phase of a new ASP.NET project.  Currently I'm evaluating the various software components and packages I'm going to use to put this project together.  With all of the hype surrounding Dependency Injection, I've decided to give it a try in this new project.  The two most popular frameworks for DI, as far as I can tell, are Spring.NET and StructureMap.

I'm leaning towards Spring.NET simply because it offers so much more besides DI.  I can, however, appreciate the XML-less features present in StructureMap 2.0.  I'm not sure whether that feature is important enough to choose StructureMap over another offering.

I'm hoping the ASP.NET community can lend some advice as to which framework to use.  Of all of the available options, which would you choose and why?




Book Review: Managing Software Development with Trac and Subversion

Tue, 05 Feb 2008 14:08:06 GMT

I just finished an interesting book, "Managing Software Development with Trac and Subversion".  Trac, a ticket management system, and Subversion, a source control management system, are open source software that are very popular in the community.  I've used each extensively and really enjoy what each of the solutions bring to the table over their competition.

The author does an excellent job explaining everything you need for getting an environment set up.  By the end of this book you'll understand the setup, configuration, and usage of each of these tools, in addition to Apache.

I would highly recommend this book to anyone looking for a free solution to project management and source code management.  It's a rather quick read at 120 pages but enjoyable and useful.




Book Review: Build Your Own ASP.NET 2.0 Web Site Using C# & VB, 2nd Edition

Fri, 25 Jan 2008 16:25:27 GMT

Over the last few weeks I've been working on finishing the latest book from SitePoint on ASP.NET, "Build Your Own ASP.NET 2.0 Web Site Using C# & VB, 2nd Edition".  The authors did a great job on this book.  It's fit for a beginner and does a wonderful job of teaching the basics of getting started in ASP.NET.  Many books skimp on the things you need before coding can begin, or they leave it out completely.  Here you'll find plenty of help and suggestions for using the most modern tools available to a new ASP.NET developer.

This book provides you with the background necessary for building ASP.NET applications.  It covers what nearly every introduction book covers, the ASP.NET controls, data access, master pages, and so on.  What sets it apart from most other books is how clearly the material is presented to the reader.  You won't find some golden piece of information you've never heard before but that's not the focus of the book.  For a beginner, it's a perfect choice.




Book Review: ASP.NET Data Presentation Controls Essentials

Thu, 17 Jan 2008 15:01:20 GMT

Not long ago I received an email from someone at Packt Publishing asking if I would review their latest ASP.NET book.  I gladly accepted as this is something I'd like to do more of.  I have another book on my bedside table waiting for a review and I'm in the middle of performing a technical edit of a book due for publication in July.  I'm thoroughly enjoying this kind of work and hope to continue it.  More on that in a future entry I imagine.

The book is called ASP.NET Data Presentation Controls Essentials.  This book is clearly marked as not being for beginners to the ASP.NET framework and I would suggest potential readers follow that warning.  The book is littered with helpful snippets of C# code showing you how to obtain data-driven output in your ASP.NET pages.  These snippets can be confusing if you're not fairly comfortable with the ASP.NET framework and the event model.  There are not that many instances of a full walk-through in the examples provided, so it's hard to follow unless you know what you're doing.  I personally found no trouble in keeping up with the book.  So, beginners, you've been warned. :)

The author has a clear understanding of the subject matter and it shows in this book.  The topics presented cover a solid portion of data access and presentation in ASP.NET.  I do wish there had been some introduction to ADO.NET at the very beginning of the book.  Being as ADO.NET is the fundamental building block to this book, I think it would have been a welcome addition.  The book itself is just over 200 pages that are broken down into 8 chapters.  At a $40 list price in the US, that's a hard sell to many in the technology world.  A chapter or two in some of the background required for the text could have helped this potential problem for would-be buyers.  It will not be a concern to everyone but the technology group is quite sensitive to the "price per page" ratio found in their technical materials.

As a first edition, there are a number of formatting and technical mistakes present in this book.  I noticed a specific code example towards the beginning of the book where quotations had been replaced by another character, which certainly would not compile and run for the reader.  A reader with C# experience would notice this instantly, but it's a mistake that should have been corrected.  The indentation of the code examples in this book are widely varied.  As a developer, it's fundamental to see correct formatting in code, and a book should hold that to a higher standard.  I also noticed a few instances of code that was simply formatted in such a way that made it invalid.  It would not compile if sitting in Visual Studio.  Again, something an experience reader would catch easily and wouldn't impede their progress through the book.

Overall, I liked the book.  It contains valuable information if you need a lesson in data presentation controls for ASP.NET.  If you are considering this book, I would pick it up at your local book store and determine if the content is what you're looking for and whether the list price can be justified to you.  Even with the technical mistakes and being a quick read, it will be a worthwhile purchase to many developers looking to understand the data presentation controls available in ASP.NET.




Strongly-Typed Session in ASP.NET

Wed, 09 Jan 2008 16:52:00 GMT

Session state is a very useful tool for an ASP.NET developer.  I use the Session object in every project.  I use it to store information related to the current user that I need quick access to throughout their visit.  It's important not to overuse the Session object but rather to store quick bits of information that need to persist over a single, or multiple, post-backs. The most painful part of using the Session object built-in to the ASP.NET framework is the error prone nature of getting and setting variables inside of the Session object.  The common usage of getting something out of Session looks like  this:Product product = Session["MyProduct"] as Product; Sure, it's simple enough and makes sense.  However, there is the potential to forget the name of the object you'd like to retrieve.  Wouldn't it be nice if the Session was a strongly-typed object that wouldn't allow for this mistake? In various projects I've been using what I call the SessionWrapper.  I can't take credit for the name or the idea, as it was something a past co-worker of mine opened my eyes to.  However, his implementation was different than mine in that you simply stored the SessionWrapper object itself in Session and accessed it in your pages.  The usage looked like this:SessionWrapper sessionWrapper = Session["SessionWrapper"] as SessionWrapper; sessionWrapper.Product = new Product(); I wanted to get away from touching the Session object in my presentation code.  Why couldn't I simply say:SessionWrapper.Product = new Product(); With this goal, my implementation of the SessionWrapper was created.  The key is using the HttpContext to interact with the Session object while not being required to inherit the Page class.  Doing this allows us to access the Session object in a static manner, creating the usage scenario we desire.  I've included a full Visual Studio 2008 solution at the bottom of this post.  Make sure you check that out.  Here's the code for the SessionWrapper class:using System; using System.Web; namespace SessionWrapperExample { public static class SessionWrapper { public static Product Product { get { if (null != HttpContext.Current.Session["SessionWrapperProduct"]) return HttpContext.Current.Session["SessionWrapperProduct"] as Product; else return null; } set { HttpContext.Current.Session["SessionWrapperProduct"] = value; } } } } Download the Solution: SessionWrapperExample.zip [...]



Microsoft ASP.NET MVC

Mon, 07 Jan 2008 21:38:00 GMT

By now we've nearly all heard of the ASP.NET MVC framework available in CTP form. The Model View Controller architecture has been around for quite some time but more popularly in the desktop world. Java has seen its share of MVC web frameworks over the years and just a few years ago Ruby on Rails crashed the party with its own MVC implementation for a rapid development environment. Once Ruby on Rails hit, all of a sudden MVC was all the rage. It wasn't long before these frameworks became available as extensions for ASP.NET. Microsoft has now joined the party with an official feature due towards the middle of 2008. In the last few weeks the ASP.NET team has shipped a CTP release for feedback and to get people started with the technology. I've looked at it quite a bit myself and I'm loving what I've seen thus far.

There are a number of reasons to be excited about this framework. Some of the biggest are separation of concerns, testability, and performance.

Separation of concerns allows you, the developer, to create self aware components that don't heavily depend on another un-related component to function. Think about removing the logic of your postback event in ASP.NET 2.0. Take that code and move it somewhere more centralized that will be used by similar web views. That concept is the relationship between the Controller and the View. The View should simply display something while the Controller should tell it what to display. The Model describes the data and is used by your Controllers and Views as something I like to think of as a transitional object.

Testability is a major concern with most developers these days. Currently automated unit testing is nearly impossible with the current Web Forms architecture present in ASP.NET. Sure, you can unit test your data and business layers. However, once these layers reach the presentation layer, testing expected behavior just isn't possible in an automated fashion. The ASP.NET MVC framework allows testability through the separation of concerns along with the way a Controller will dictate which View is rendered. That functionality allows for easy testability.

The final reason I'll discuss here is performance. ViewState is a piece of magic all too often by the Web Forms architecture and simply is a bloated method for persisting data across HTTP requests. The ASP.NET MVC framework will remove this dependency and will provide better performing environment for our web applications.

I'm in the planning stages of a new project and really investigated whether I should begin ASP.NET MVC development. Since it's so new I'm not going to risk it but I encourage everyone to keep an eye on this project. I'll definitely be doing that and will be all over a release closer to RTM.

Resources:
ScottGu - MVC Tag
Phil Haack - ASP.NET MVC PM

(image)