Attempt to bind struct to interface throws "The type .. cannot be constructed. You must configure the container to supply this value"

Topics: Enterprise Library Core, General discussion
Aug 12, 2011 at 5:31 AM

I have next code:

public interface ISomething { }

public struct ConcreteSomething : ISomething { }

var container = new UnityContainer();
container.RegisterType(typeof(ISomething), typeof(ConcreteSomething));
var s = container.Resolve<ISomething>();

and it throws:

Resolution of the dependency failed, type = "ConsoleApplication1.ISomething", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type ConcreteSomething cannot be constructed. You must configure the container to supply this value.

So it it possible to bind a struct to an interface in Unity?

Aug 12, 2011 at 5:54 AM

Hi,

You can post this to Unity Forum (http://unity.codeplex.com/discussions) to get a better answer :)

 

Aug 12, 2011 at 5:58 AM

Oops! Thank you.

Moderators, please delete the topic.