Unity 1.2 + open generics + xml config

Dec 4, 2009 at 9:18 PM

We're having some trouble with the following configuration:

public class WorkQueue<T> : IWorkQueue<T>
{
     public WorkQueue(IDispatcher<T> dispatcher){...}
}

So far, the correct XML configuration has escaped us, with Unity complaining that WorkQueue<T> doesn't have a constructor that takes an argument of type T (which is correct *laugh*).  Can anyone suggest what the correct XML configuration would look like for this setup?

Many thanks!

Dec 8, 2009 at 1:22 AM

You should have at least two type mappings, 1 for the IWorkQueue and 1 for the IDispatcher:

Supposing they are defined under the namespace, CustomObjects, here's a way to do it:

<type type="CustomObjects.IDispatcher`1, CustomObjects" mapTo="CustomObjects.Dispatcher`1, CustomObjects" />
<type type="CustomObjects.IWorkQueue`1, CustomObjects" mapTo="CustomObjects.WorkQueue`1, CustomObjects" />
 

By the way, are you using Unity 1.2?  If you are using the 1.1 version, you might be encountering this bug - http://unity.codeplex.com/Thread/View.aspx?ThreadId=27231 

 Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com

 
 
Dec 8, 2009 at 2:07 PM

Yes, we're on 1.2, and the main item here that tripped us up was that our IDispatcher<T> implementation looked like so:

public class WorkDispatcher : IDispatcher<ParserWorkItem>
{
     //...
}
Note the absence of the T generic on the concrete type name...Unity does not seem to work with this type of configuration.  When we added the <ParserWorkItem> to WorkDispatcher, everything came together nicely.  Is this a known bug?  While the above is perfectly legal C#, is it possibly not "correct" enough to fit into the target scenarios that Unity solves?

Thanks!

Dec 9, 2009 at 2:12 AM

Really? It should work...it just did for me.  I just changed my typemapping for IDispatcher<T> to map to the WorkDispatcher...

<type type="CustomObjects.IDispatcher`1, CustomObjects" mapTo="CustomObjects.WorkDispatcher, CustomObjects" />

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com