Simon Lomax
Simon Lomax

Reputation: 8972

Structure Map 2.6.1

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

Upvotes: 0

Views: 289

Answers (1)

chrissie1
chrissie1

Reputation: 5029

I think this should do it.

_container = new Container();
_container.Configure(x =>
                         {
                             x.For(typeof (IFilterConverter<>)).Use(typeof (FilterConverter<>));
                         });

Upvotes: 1

Related Questions