Re: HttpHostConfiguration pattern too inflexible

Topics: Web Api
May 15, 2011 at 11:50 PM
Switching to HttpHostConfiguration.Create() solves it too.

/kzu

--
Daniel Cazzulino | Developer Lead | MS MVP | Clarius Consulting | +1 425.329.3471


On Sun, May 15, 2011 at 20:48, Daniel Cazzulino <kzu@clariusconsulting.net> wrote:
It's because of the explicit interface implementation :(.

Casting to the builder interface allows me to pass a resource factory instance, like so:

var configuration = (IHttpHostConfigurationBuilder)new HttpHostConfiguration();
configuration.SetResourceFactory(new AutofacResourceFactory(container));

Moving on...

/kzu

--
Daniel Cazzulino | Developer Lead | MS MVP | Clarius Consulting | +1 425.329.3471


On Sun, May 15, 2011 at 20:44, Daniel Cazzulino <kzu@clariusconsulting.net> wrote:
The built-in configuration factory follows a pattern where the properties (such as InstanceFactory) are readonly (internal set) and the fluent setters (i.e. SetResourceFactory<T>) require the T to have a public default constructor (new() constraint).

This seems unnecessarily limiting. I cannot provide a ready-built resource factory (i.e. with some external dependencies already built-in) in any way, unless I go and implement the entire IHttpHostConfigurationBuilder interface.

The setter for the properties should be at least protected internal set, so that from a custom configuration I can set the property to an instantiated value.

Concrete case: I'm creating an AutofacResourceFactory, which needs the IContainer to pull instances from.

Maybe I'm just missing something obvious :)

/kzu

--
Daniel Cazzulino | Developer Lead | MS MVP | Clarius Consulting | +1 425.329.3471