views:

91

answers:

4

My asp.net controllers action takes the FormCollection as a parameter.

I then loop through my own collection, do a lookup in the form collection for a value etc.

I moved all my code to my business logic layer, and just call my business logic layer in my action like:

SomeManager.Update(formCollection);

But I am feeling a bit weary passing in a formcollection to my business logic layer.

Do I really have a choice here? any other ideas?

or is it perfectly fine?

+8  A: 

You Business Logic Layer is really your Domain Model, and a Domain Model should be expressed in a technology-agnostic way; i.e. without dependencies on any particular technologies such as ASP.NET MVC, WPF, WCF, EF, NHibernate or whatnot.

It's best if you can express your Domain Model as POCOs (Plain Old CLR Objects), but, as you are already suspecting, this precludes FormCollections and other ASP.NET MVC-specific types.

It would be better if you were able to express the Update method as a method that takes a list of Domain Objects as input.

This would mean that you need to translate the FormCollection to strongly typed Domain Objects before you pass it on to the update method. You would need a Mapper to do that. You can either write your own custom mapper or use AutoMapper for this.

Mark Seemann
I already have a strongly typed collection that I am using the form to update, I'll just loop through the forms collection and update the object, then pass to BLL to update db.
mrblah
Instead of using the form collection, why don't you use a custom view model? This way the built-in modelbinder will do the mapping for you.
Jaco Pretorius
+3  A: 

The rule of thumb is that you shouldn't reference anything from System.Web.XXX in your business layer(s) or lower. In this case you could rather use custom model binders to get away from using FormCollection.

See this post for more on creating model binders.

Mark Gibaud
A: 

why not create some kind of dto (data transfer object) then populate and then pass that through. it would be a little cleaner.

Blounty
A: 

I would create a mapper class that takes a FormCollection and returns an instance, or updated instance of a class.

ManagerMapper.Create(formcollection) or ManagerMapper.Update(SomeManager, formcollection)

NerdFury