2

Given an interface

public interface ISomething<TA, TB>
    where TA : class
    where TB : class, ISomeOtherInterface
{
    object SomeMethod(TSource source, TDestination destination);
}

And a class implementing it

public class Something<TA, TB> : ISomething<TA, TB>
    where TA : class
    where TB : class, ISomeOtherInterface
{
    public object SomeMethod(TA source, TB destination)
    {
        // lots of really important code.
    }
}

I've tried registering the implementation both via For().Use() and ConnectImplementationsToTypesClosing()

var container = new Container();

container.Configure(config => {
    config.For(typeof(ISomething<,>))
          .Use(typeof( Something<,>));

    config.Scan(_ => {
        _.AssemblyContainingType(typeof(Something<,>));
        _.ConnectImplementationsToTypesClosing(typeof(ISomething<,>));
    });
});

But to no avail; every call to container.GetInstance<ISomething<Foo, Bar>>() fails with a StructureMapConfigurationException:

No default Instance is registered and cannot be automatically determined for type 'ISomething<Foo, Bar>'

There is no configuration specified for ISomething<Foo, Bar>

1.) Container.GetInstance(ISomething<Foo, Bar>)

Calling container.WhatDoIHave() on the very same container yields

ISomething<TA, TB> My.Project.Namespace Transient Something<TA, TB> (Default)

though. Also, calling container.GetInstance<Something<Foo, Bar>>() (referencing the implementation as opposed to the interface) works just fine.

What am I missing?

vzwick
  • 11,008
  • 5
  • 43
  • 63
  • `ConnectImplementationsToTypesClosing` does exactly that, but, unfortunately all you have as concrete type is yet another open generic. Which StructureMap will not connect to `ISomething`. Basically, you are never mapping the interface `ISomething` to the implementation `Something`. That's what it's actually telling you – Silviu Preda Jan 30 '18 at 07:22

0 Answers0