Having troubles using Generic interfaces

Nov 14, 2008 at 4:28 AM
Given the following classes and unity container setup the Resolve call fails with
"System.InvalidOperationException: The current type, IChainHandler`1[MyRequestObject], is an interface and cannot be constructed. Are you missing a type mapping?"

What am I missing ?

public interface IChainHandler<T>
 IChainHandler<T> Successor { get; set; }
 bool Evaluate( T request );

public class MyRequestObject
 public string TheValue { get; set; }

public class ChainHandler : IChainHandler<MyRequestObject>
 #region IChainHandler<MyRequestObject> Members

 public IChainHandler<MyRequestObject> Successor { get; set; }

 public bool Evaluate( MyRequestObject request )
  return true;

 public ChainHandler()


IUnityContainer newContainer = new UnityContainer();
 .RegisterType( typeof( IChainHandler<MyRequestObject> ), typeof( ChainHandler ), "ChainHandler" )
IChainHandler<MyRequestObject> resolved = newContainer.Resolve<IChainHandler<MyRequestObject>>();

Nov 14, 2008 at 5:14 AM

You should pass "ChainHandler" in the call to Resolve method since you specified a name when you register it in the container.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Nov 15, 2008 at 12:17 AM

thanks Sarah.  Talk about spot the obvious.  Was was using the ResolveAll method and not getting any instances back so switched to the Resolve method and forgot to include the name.