views:

42

answers:

1

Hi,

In my current project I'm currently trying to replace the Windsor IoC in favour of structure map (2.6.1). But having a bit of problem registering some generic types. How would I register IFilterConverter<T> to use FilterConverter<SomeSpecificType>. I've tried ConnectImplementationsToTypesClosing(IFilterConverter) but from what I've read (Jimmy Bogard's article) I would need a concrete type defined like so:- SomeConcreteType : IFilterConverter<SomeSpecificType> for that to work and I don't have that.

So to reiterate if I have a type that takes a constructor argument IFilterConverter<SomeSpecificType>, I want structure map to provide me with FilterConverter<SomeSpecificType>.

With Windsor I was using the XML config option (which I want to get away from) But all I did was just set up the configuration like so:

<component id="IFilterConverter" service="SomeNamespace.IFilterConverter`1, SomeNamespace" type="SomeNamespace.FilterConverter`1, SomeNamespace" lifestyle="PerWebRequest">

How do I do the equivalent in SM (using code, not XML config files)

Thanks

+1  A: 

I think this should do it.

_container = new Container();
_container.Configure(x =>
                         {
                             x.For(typeof (IFilterConverter<>)).Use(typeof (FilterConverter<>));
                         });
chrissie1
Thanks chrissie1, that did the trick.
Simon Lomax