Fluent.Interface


Category Archive

The following is a list of all entries from the Agile category.

TDD on show with ASP.NET MVC at Mix09

Its been a long road, but ASP.NET MVC 1.0 is out and now is open source as posted on ScottGu’s blog.  Its a great milestone and one that has been paraded in front of the the Mix09 attendees in Vegas.  I can recommend setting aside the two hours required to get through Phil Haack‘s Nija preso, and Scott Hanselman‘s NerdDinner talk.

Those guys along with Rob Conery and the main man Scott Guthrie have been slaving away on a new book ASP.NET MVC 1.0 from wrox press.  

the extended forehead edition

And have been kind enough to give away from free a chapter that walks through all the steps required to create the NerdDinner sample, which includes details on:

  • Validation
  • Security tips
  • Rendering partial controls
  • Custom routing
  • Authentication/Authorization
  • AJAX (with jQuery).
  • LINQ to SQL mapping with scalar/table MSSQL functions (very cool!) 
  • Dependancy injection with MOQ

It also has 20 pages dedicated to Unit testing, and encourages using the ‘AAA’ approach: Arrange, Act, and Assert which looks like this:

[TestMethod]
public void Dinner_Should_Not_Be_Valid_When_Some_Properties_Incorrect() {
//Arrange
Dinner dinner = new Dinner() {
Title = "Test title",
Country = "USA",
ContactPhone = "BOGUS"
};
// Act
bool isValid = dinner.IsValid;
//Assert
Assert.IsFalse(isValid);
}

PhilHa and ScottHa also spend a good amount of time covering red/green/refactor in their videos, and why it is important to have the test fail first.  Great Stuff!


Microsoft’s Data Programmability team listening to the community

While Microsoft’s Entity Framework continues to add new features with release of SP1.  It still doesn’t go anyway to supporting persistent ignorant domain models in the way the NHibernate does.  As i blogged about previously, this has been so unpopular that a PostSharp plugin has been developed to inject the nesseacary bits to support the EF at compile time.

However the good news is that a delegation of great minds including Eric Evans and Jimmy Nilsson (both with great DDD books) will be brain storming on ways to improve the next release – especially in relation to Domain Drive Design practices.


.NET open source projects embrace C#3

Every now and then you come across an open source initiative that has taken the new C# lambdas language extensions and run with them.  My two favourite at the moment are AutoFac and Moq.  And yes they are an agile developers favourite toolbox items – a DI container and Mocking framework respectively.

AutoFac enables compile-time configuration of the container, and supports scoping object creation, so that you could have a different instance per transaction, per request etc.  And to top that off it has bench marked very well especially when using the lambdas expressions.

Moq brings the fluent interface of RhinoMocks into the lambdas world, and is equally impressive.

Both libraries have good documentation and are open sourced at google code.


Continuous Integration with VS 2008

TFS 2008 introduced Team Build which enables continuous integration.  But if you come from a traditional SVN/CruiseControl background, you will be please to know that there is also a CC.NET plugin available.

And with preview release of the powershell provider for IIS 7, it is possible to easily creating the websites, setting permissions etc without the scripting pain of the past.


Microsoft’s answer to DI with Unity

Microsoft Patterns and Practice team has released a new Dependancy Injection Framework – Unity.  This new lightweight library built on top of ‘Object Builder’ can be used stand alone or as part of the Enterprise Library 4.0 when it is released.

This is a step in the right direction and a far superior solution to the first attempts at configuration management which turned many developers off prior versions.

InfoQ has some running commentary with the lead developer on the motivations behind the standardisation.


The right balance for Dependency Injection (DI)

I agree with some remarks in Does Dependency Injection pay off in-so-far-as developers can overdue DI.

When going putting together a best practice framework for Domain-Driven Development using NHibernate i considered how best to configure the data access. NHibernate requires some additional session factory information in addition to the database connection string. In particular this references the assembly of Objects & Hbm embedded resources that map to the database + Other name/value configuration properties.

NHibernate supports a standard way of setting this configuration information. But I needed to support multiple databases (session-factories) and wanted this configuration to sit directly within the app.config, so i went about creating my own session factory configuration handler:

<nhibernate>
  <
sessionFactories>
  <
clearFactories />
  <
sessionFactory name="SessionFactoryName" connectionStringName="ConnectionStringName">
  <
settings>
  <
clear />
  <
add name="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
  <
add name="hibernate.dialect"
value="NHibernate.Dialect.MsSql2005Dialect"/>
  <
add name="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
  <
add name="hibernate.cache.provider_class"
value="NHibernate.Cache.HashtableCacheProvider,NHibernate"/>
  <
add name="hibernate.cache.use_query_cache"
value="true"/>
  </
settings>
  <
assemblies>
  <
clear />
  <
add assembly="Domain.Common" />
  </
assemblies>
  </
sessionFactory>
  </
sessionFactories>
</
nhibernate>

I structured the code in such a way that one IDaoFactory interface that was initialized with a SessionFactory name, and it passed this name down to its respectify IDao (repository) implementations that would then load the configuration information for loading the NHibernate ISession. So in essense I was not injecting the configuration information for the ojbect, but more a pointer so it could load the information. And by seperating the IDao contract, it makes it very easy to create a Dao stub that could be used for unit testing purposes.

It is also worth noting that in the top web layer i use Castle Windsor to inject the SessionFactory name’s into the IDaoFactory objects, so as to avoid hard coding any configuration information:

<castle>
  <
components>
  <
component id="primaryDaoFactory"
type="Data.NHibernateDaoFactory, Domain.Data"
service="Domain.Interfaces.IDaoFactory, Domain.Common">
<
parameters>
<
sessionFactoryName>DCDS</sessionFactoryName>
</
parameters>
</
component>
</
components>
</
castle>

This is only introduced at the web layer, so as to avoid the dependency on the Castle framework throughout the Domain model / data libraries. So to surmise I use DI techniques in constructing objects, but minimize the injection points so as to avoid develop confusion on how/when objects are initialized.


What I’m excited about – Agile goodness of DDD/TDD/ORM

I have spent a lot of time resarching the internet (and in particular other people blogs) for information on my specific agile topics of interest:

With all that great info out there, I thought it wouldn’t hurt to have another filtered view of the world. So I will be following up with some articles on my own.

Stay tuned,

Julian.