MEF, Autofac and OSGi.NET

Jul 8, 2013 at 11:58 AM
Hi,

how i can use MEF in the OSGi.NET Framework?

I tried to register my parts in...

UIShell.IoCPlugin.IocContainer.Complete()
    string[] folders = System.IO.Directory.GetDirectories(HostingEnvironment.MapPath(FrameworkExtensionsWebPath), "*", System.IO.SearchOption.AllDirectories);
    AggregateCatalog aggregateCatalog = new AggregateCatalog();

    foreach (string folder in folders)
    {
        DirectoryCatalog catalog = new DirectoryCatalog(folder);
        aggregateCatalog.Catalogs.Add(catalog);
    }

    containerBuilder.RegisterComposablePartCatalog(aggregateCatalog);
           
    var container = containerBuilder.Build();
                              
    runtime.AddService(typeof(IContainer), container);
My class DLL (without Activator or Manifest.xml etc.)
namespace MefPlugin1
{
    [Export(typeof(IWriter))]
    public class Writer : IWriter
    {

        public string getDefaultText()
        {
            return "Hello World";
        }

    }
}
My Plugin (with Activator and Manifest.xml)
namespace FoobarPlugin.Controllers
{
    public class FoobarPluginController : Controller
    {
        //
        // GET: /FoobarPlugin/
        [Import(typeof(MefPlugin1.IWriter))]
        private MefPlugin1.IWriter _write;
   
        public ActionResult Index()
        {
            ViewBag.Title = _write.getDefaultText();
            return View();
        }

    }
}
Can anybody help me, please? :)

thanks
Marcus
Coordinator
Jul 17, 2013 at 6:07 AM
Hi,
What you need to do is simply Compose your controller instance by MEF after it be created,
please check out how I did it with Autofac.

Best wishes,
Joey