3

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.

Community
  • 1
  • 1
user3792159
  • 111
  • 2
  • 13
  • Were you able make this work? I am considering implementing pluggable WebAPI service and could not find anything on the web. – Bhuvan Dec 08 '15 at 23:21

1 Answers1

1

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

user3792159
  • 111
  • 2
  • 13