MyControllerBase contains a reference to the data store and MyControllerFactory attaches the controller to the instance of the data store. This makes the controllers more testable because i can mock the data store.
However, the above code means "use MyControllerFactory when creating a controller of type MyControllerBase",
NOT when creating a controller which derives from MyControllerBase. So i would have to repeat this line for each controller.
Changing the behaviour of this will make it much easier to provide a ControllerFactory for a set of related Controllers
Use ControllerBuilder.SetDefaultControllerFactory(typeof(MyControllerFactory)). Then you can implement the base class resolution logic in your own factory and you do not need to call SetControllerFactory for all of your controllers.
That's what i've had to do. But if i have 2 or more "families" of controllers, each with their own base class, this gets a bit ugly.
My point is that the idea of SetControllerFactory is useful for when you don't want to override the behaviour for every controller. But it could be even more useful if it did a bit more work for me.
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
SetControllerFactory suggestion
Dec 30, 2007 11:51 PM|LINK
MyControllerBase contains a reference to the data store and MyControllerFactory attaches the controller to the instance of the data store. This makes the controllers more testable because i can mock the data store.
However, the above code means "use MyControllerFactory when creating a controller of type MyControllerBase", NOT when creating a controller which derives from MyControllerBase. So i would have to repeat this line for each controller.
Changing the behaviour of this will make it much easier to provide a ControllerFactory for a set of related Controllers
sergiopereir...
Member
227 Points
61 Posts
Re: SetControllerFactory suggestion
Dec 31, 2007 12:09 AM|LINK
Got my vote.
Sergio Pereira
http://devlicio.us/blogs/sergio_pereira/
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: SetControllerFactory suggestion
Dec 31, 2007 01:09 AM|LINK
Oh, and also, instead of supplying a Type, it would make much more sense if I could supply an instance of my ControllerFactory.
(i knew there was something i'd forgotten)
wcpierce
Member
47 Points
16 Posts
Re: SetControllerFactory suggestion
Dec 31, 2007 03:45 AM|LINK
Use ControllerBuilder.SetDefaultControllerFactory(typeof(MyControllerFactory)). Then you can implement the base class resolution logic in your own factory and you do not need to call SetControllerFactory for all of your controllers.
controllerfactory custom
http://blechie.com/wpierce/
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: SetControllerFactory suggestion
Dec 31, 2007 03:59 AM|LINK
That's what i've had to do. But if i have 2 or more "families" of controllers, each with their own base class, this gets a bit ugly.
My point is that the idea of SetControllerFactory is useful for when you don't want to override the behaviour for every controller. But it could be even more useful if it did a bit more work for me.