Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEF in WebApi 2.0 not resolving

I'm setting up MEF in a WebApi 2.0 Initially I looked at this example http://www.kennytordeur.blogspot.com/2012/08/mef-in-aspnet-mvc-4-and-webapi.html but in a more recent post How to integrate MEF with ASP.NET MVC 4 and ASP.NET Web API I saw that "DefaultControllerFactory with MVC is now an outdated technique".

I setup the MefDependencyResolver and the MefConfig based on the later post, but the webapi controller is not resolving it because the value is still null, also, I noticed the answer from the second post doesn't call compose parts. Does anyone know what I might be missing?

I'm calling MefConfig.RegisterMef() in an Owin Startup.cs class. Before in the startup class I had:

catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
CompositionContainer container = new CompositionContainer(catalog, true);
container.ComposeParts(this);
configuration = new HttpConfiguration();
configuration.DependencyResolver = new MefDependencyResolver(container);
app.UseWebApi(configuration);

With this other method, the import was still not being resolved. So I've tried those two things.

like image 370
user3792159 Avatar asked Dec 15 '25 12:12

user3792159


1 Answers

I was checking the constructor, when I debug a different method the dependency has resolved.

like image 80
user3792159 Avatar answered Dec 17 '25 03:12

user3792159



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!