Posts

Interface Oriented Code Organization(IOCO)

Image
When I started experimenting with TDD  and specifically writing the test first, I had a sudden realization as I began to contemplate where should I place this new test I was about to create.  I realized that the simplest place for the test would be in a folder structure that matched the UI for a web app or the API for a web API, and then quickly realized it would be helpful to have the production code folder structure match as well. I had been working on several large complex code bases, some web apps, and some web APIs, and trying to find the code that needed to change or where to add new code wasn't obvious from the code organization. The code was organized in the layered architecture style with UI layer, Service Layer, Repository Layer, etc. kind of like the structure Microsoft uses in  "Traditional N-Layer architecture applications" . With folders for Controllers, Views, ViewModels, etc. This architecture-oriented code organization(AOCO) is really good at telling you ...

DbEntityValidationException

When calling SaveChanges  on an entity context object you can sometimes get a DbEntityValidationException  error but it doesn't give you a convenient message as to what the error(s) were.  Here is a code snippet to get a convenient message from the DbEntityValidationException  object: Try context.SaveChanges() Catch ex As DbEntityValidationException 'Capture all default Entity Framework Validation errors like required fields, text size checks etc. Dim errorMessage As New StringBuilder For Each validationResult As DbEntityValidationResult In ex.EntityValidationErrors errorMessage.AppendLine( String .Format( "Entity of type [{0}] in state [{1}] has the following validation errors:" , validationResult.Entry.Entity. GetType .Name(), validationResult.Entry.State)) For Each item As DbValidationError In validationResult.Vali...

Page.ClientScript.RegisterStartupScript not working

Had a website with a master page and in the the page_load event I was calling  Page.ClientScript.RegisterStartupScript to run some javascript based on the current state of the application. In the default.aspx page the script worked fine but in this other page the script was not getting called at all.   After much research I have learned that  Page.ClientScript.RegisterStartupScript only works if the page has a form element that has the  runat="server" set.  Once I added a form element with runat="server" to the other page the script finally started getting called the same as it did on the default.aspx page which of course had already had a form element.

ASP.NET 2.0 DropDownList EnableViewState

In ASP.NET 2.0 the  DropDownList   EnableViewState  doesn't work the same as other controls like GridView . Fortunately Anson Goldade created one that does. You can learn how here:  http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.aspnet.webcontrols/2006-02/msg00149.html

Add Charset and ContentType to ASP.NET web page

The WC3 recommends specifying the Charset and ContentType on all of your web pages. A quick and easy way to do this in a ASP.NET web site with a master page is to add this to the masterpage file: <% Response.Charset = "utf-8" %> <% Response.ContentType = "text/html" %>

system.diagnostic trace not creating file in asp.net

Image
If your S ystem .D iagnostic trace is not creating a file in asp.net make sure the the user that the website/webapp is running under has write permissions to the log file folder(default is web root ie where the web.config is). You can find the user that the website/webapp is running under by going into IIS. Go to the application pool that the website/webapp is running under and the Identity column will show the user that needs write permissions to the log file folder.

Where are UnityContainerExtensions

Image
I had wrapped a Unity container in another class and then was using it to call Resolve and only got one option in intellisense like this: But I was wanting the Resolve(Of T) option like this: Then I discovered I was missing "Imports Microsoft.Practices.Unity" at the top of the class.  Once I added that then the UnityContainerExtensions became available.