2
Vote

MefContrib.MVC3

description

Hi All,
I'm using MefContrib.MVC3 and have a rather bizar issue.
 
When i use DependencyResolver.Current.GetServices<T>() it returns my items twice.
 
I made an interface IStartupTask and decorated it with the InheritedExport(typeof(IStartupTask))
I have some base class implementing it and finally derive this into my concrete tasks, beside the interface i have no other attributes on these.
When I call DependencyResolver.Current.GetServices<T>().ToArray() it gives me 4 items, but I should have only 2.
Any clues on how I can debug/solve this ?
I tried to add PartCreationPolicy as shared, I would expect this to solve the issue (in a bad way i agree) but still 4 items are returning.
Edit :
I've reflectored the code and did a couple of other tests. This seams to occure with anything that gets imported with ImportMany attribute also.
 
Regards

comments

sebdg wrote Jul 17, 2011 at 5:40 PM

I apparently fixed my issue, but i might have broken the logic in there.
To resume i had to create a custom dependency resolver and overwritten the way the Container property works
The small change i did is not passing in any export provider. to the container that is hold on a request base.
Now my tasks and controllers are resolved only once.

public CompositionContainer Container
    {
        get
        {
            if (!CurrentRequestContext.Items.Contains("__CompositionDependencyResolver_Container"))
            {
                CurrentRequestContext.Items.Add("__CompositionDependencyResolver_Container", new CompositionContainer(this.filteredCatalog, true, new ExportProvider[] {}));
            }
            return (CompositionContainer) CurrentRequestContext.Items["__CompositionDependencyResolver_Container"];
        }
    }

wrote Sep 8, 2011 at 9:56 PM

Alive43 wrote Sep 8, 2011 at 9:59 PM

Hi,
I've the same issue described above. All resolutions using the [ImportMany] attribute produces twice instances. Tried using PartCreationPolicy as long as PartCreationScope and with no luck.
Any thoughts of the authors would be appreciated.
Thanks!

wrote Feb 14, 2013 at 8:47 PM