Monday, October 24, 2011

Composition Root

I'm reading Dependency Injection in .Net by Mark Seemann

In response to http://blog.ploeh.dk/2011/07/28/CompositionRoot.aspx

I'm only up to reading mid-way through your chapter on doing it right (and jumped to the asp.net webforms composition root after reading this blog post), but here is more of my reasoning.

The catch comes when you look at the behavior, and you realize that there is hardly any behavior on these objects, making them little more than bags of getters and setters. Indeed often these models come with design rules that say that you are not to put any domain logic in the the domain objects. AnemicDomain Models - Martin Fowler


It becomes a 'real' domain model when it contains all (or most) of the behaviour that makes up the business domain (note I'm emphasising business logic, not UI or other orthogonal concerns). Anemic Domain Models - Stack overflow

I don't feel that this is headed into an Anemic domain model as the domain model assembly would contain all behaviors specific to the domain.

  Designs that share very little state or, even better, have no state at all tend to be less prone to hard to analyze bugs and easier to repurpose when requirements change. Blog article - makes sense but i could be missing multiple boats here.

The domain would have zero state, and would depend on interfaces not DTOs. This would make test-ability and analysis simple.

 Motivation for DTOs in the interfaces layer: presentation and persistence could all share the DTOs rather than having them duplicated in either place.
Barring that perceived gain, then the shared layer across all would just be interfaces.

 The UI could depend on interfaces only, but the same assembly would contain DTOs that the presentation layer and any persistence could share without having to be duplicated/rewritten. So the domain is completely persistence and presentation ignorant.

Wednesday, October 19, 2011

Routing except webforms requests

I have a legacy webforms (.aspx) project that I'm sliding routing and MVC3 into. I needed a route that would not prevent the default page from being handled by IIS, but would allow all other controller style routing.  How do you make a regex that only fails uri's that have .aspx or .axd in them?

Then I thought well I still don't want anything that doesn't look like an mvc route (things that end in .foo or .fooo)  Sounds like a crazy negative regex.
Here's the regular expression:

^(.(?!\.[a-zA-Z0-9]{3,}))*$


Match anything that doesn't look like a file extension 


And here's the routeAdd in global.asax


static void RegisterRoutes(RouteCollection routes)
  {

     routes.MapRoute("mvc", "{controller}/{action}/{id}",defaults: new{action="index",id=""}, constraints:new{controller=@"^(.(?!\.[a-zA-Z0-9]{3,}))*$"});

  }