0

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

Simon Lomax
  • 8,714
  • 8
  • 42
  • 75
  • Out of curiosity - why are you migrating from Windsor to StructureMap? – Krzysztof Kozmic Jul 06 '10 at 10:32
  • No major reason, just that I've heard and read a lot about structure map and wanted to give it a try. As I said in my OP I was using the config file option with Windsor and didn't care for it much. I do realise I could have just switched to configuring Windsor via c# code but thought I'd give SM a try. I'm in no way suggesting that SM is any way "better" than Windsor. It was just really curiosity. – Simon Lomax Jul 06 '10 at 10:37

1 Answers1

1

I think this should do it.

_container = new Container();
_container.Configure(x =>
                         {
                             x.For(typeof (IFilterConverter<>)).Use(typeof (FilterConverter<>));
                         });
chrissie1
  • 5,014
  • 3
  • 26
  • 26